PHP 클래스 Webmozart\Json\JsonEncoder

부터: 1.0
저자: Bernhard Schussek ([email protected])
파일 보기 프로젝트 열기: webmozart/json 1 사용 예제들

공개 메소드들

메소드 설명
__construct ( JsonValidator $validator = null ) Creates a new encoder.
encode ( mixed $data, string | object $schema = null ) : string Encodes data as JSON.
encodeFile ( mixed $data, string $path, string | object $schema = null ) Encodes data into a JSON file.
getArrayEncoding ( ) : integer Returns the encoding of non-associative arrays.
getMaxDepth ( ) : integer Returns the maximum recursion depth.
getNumericEncoding ( ) : integer Returns the encoding of numeric strings.
isAmpersandEscaped ( ) : boolean Returns whether ampersands (&) are escaped.
isDoubleQuoteEscaped ( ) : boolean Returns whether double quotes (") are escaped.
isGtLtEscaped ( ) : boolean Returns whether greater than/less than symbols (>, <) are escaped.
isPrettyPrinting ( ) : boolean Returns whether JSON strings are formatted for better readability.
isSingleQuoteEscaped ( ) : boolean Returns whether single quotes (') are escaped.
isSlashEscaped ( ) : boolean Returns whether forward slashes (/) are escaped.
isTerminatedWithLineFeed ( ) : boolean Returns whether JSON strings are terminated with a line feed.
isUnicodeEscaped ( ) : boolean Returns whether unicode characters are escaped.
setArrayEncoding ( integer $encoding ) Sets the encoding of non-associative arrays.
setEscapeAmpersand ( boolean $enabled ) Sets whether ampersands (&) should be escaped.
setEscapeDoubleQuote ( boolean $enabled ) Sets whether double quotes (") should be escaped.
setEscapeGtLt ( boolean $enabled ) Sets whether greater than/less than symbols (>, <) should be escaped.
setEscapeSingleQuote ( boolean $enabled ) Sets whether single quotes (") should be escaped.
setEscapeSlash ( boolean $enabled ) Sets whether forward slashes (") should be escaped.
setEscapeUnicode ( boolean $enabled ) Sets whether unicode characters should be escaped.
setMaxDepth ( integer $maxDepth ) Sets the maximum recursion depth.
setNumericEncoding ( integer $encoding ) Sets the encoding of numeric strings.
setPrettyPrinting ( boolean $prettyPrinting ) Sets whether JSON strings should be formatted for better readability.
setTerminateWithLineFeed ( boolean $enabled ) Sets whether JSON strings should be terminated with a line feed.

메소드 상세

__construct() 공개 메소드

Creates a new encoder.
public __construct ( JsonValidator $validator = null )
$validator JsonValidator

encode() 공개 메소드

If a schema is passed, the value is validated against that schema before encoding. The schema may be passed as file path or as object returned from JsonDecoder::decodeFile($schemaFile). You can adjust the decoding with the various setters in this class.
public encode ( mixed $data, string | object $schema = null ) : string
$data mixed The data to encode
$schema string | object The schema file or object
리턴 string The JSON string

encodeFile() 공개 메소드

Encodes data into a JSON file.
또한 보기: encode
public encodeFile ( mixed $data, string $path, string | object $schema = null )
$data mixed The data to encode
$path string The path where the JSON file will be stored
$schema string | object The schema file or object

getArrayEncoding() 공개 메소드

Returns the encoding of non-associative arrays.
public getArrayEncoding ( ) : integer
리턴 integer One of the constants {@link JSON_OBJECT} and {@link JSON_ARRAY}

getMaxDepth() 공개 메소드

A depth of zero means that objects are not allowed. A depth of one means only one level of objects or arrays is allowed.
public getMaxDepth ( ) : integer
리턴 integer The maximum recursion depth

getNumericEncoding() 공개 메소드

Returns the encoding of numeric strings.
public getNumericEncoding ( ) : integer
리턴 integer One of the constants {@link JSON_STRING} and {@link JSON_NUMBER}

isAmpersandEscaped() 공개 메소드

If true, ampersands will be escaped as "\u0026". By default, ampersands are not escaped.
public isAmpersandEscaped ( ) : boolean
리턴 boolean Whether ampersands are escaped

isDoubleQuoteEscaped() 공개 메소드

If true, double quotes will be escaped as "\u0022". By default, double quotes are not escaped.
public isDoubleQuoteEscaped ( ) : boolean
리턴 boolean Whether double quotes are escaped

isGtLtEscaped() 공개 메소드

If true, greater than will be escaped as "\u003E" and less than as "\u003C". By default, greater than/less than symbols are not escaped.
public isGtLtEscaped ( ) : boolean
리턴 boolean Whether greater than/less than symbols are escaped

isPrettyPrinting() 공개 메소드

If true, line breaks will be added after object properties and array entries. Each new nesting level will be indented by four spaces. By default, pretty printing is not enabled.
public isPrettyPrinting ( ) : boolean
리턴 boolean Whether JSON strings are formatted

isSingleQuoteEscaped() 공개 메소드

If true, single quotes will be escaped as "\u0027". By default, single quotes are not escaped.
public isSingleQuoteEscaped ( ) : boolean
리턴 boolean Whether single quotes are escaped

isSlashEscaped() 공개 메소드

If true, forward slashes will be escaped as "\/". By default, forward slashes are not escaped.
public isSlashEscaped ( ) : boolean
리턴 boolean Whether forward slashes are escaped

isTerminatedWithLineFeed() 공개 메소드

By default, JSON strings are not terminated with a line feed.
public isTerminatedWithLineFeed ( ) : boolean
리턴 boolean Whether JSON strings are terminated with a line feed

isUnicodeEscaped() 공개 메소드

If true, unicode characters will be escaped as hexadecimals strings. For example, "ü" will be escaped as "\u00fc". By default, unicode characters are escaped.
public isUnicodeEscaped ( ) : boolean
리턴 boolean Whether unicode characters are escaped

setArrayEncoding() 공개 메소드

By default, non-associative arrays are decoded as JSON arrays.
public setArrayEncoding ( integer $encoding )
$encoding integer One of the constants {@link JSON_OBJECT} and {@link JSON_ARRAY}

setEscapeAmpersand() 공개 메소드

If true, ampersands will be escaped as "\u0026". By default, ampersands are not escaped.
public setEscapeAmpersand ( boolean $enabled )
$enabled boolean Whether ampersands should be escaped

setEscapeDoubleQuote() 공개 메소드

If true, double quotes will be escaped as "\u0022". By default, double quotes are not escaped.
public setEscapeDoubleQuote ( boolean $enabled )
$enabled boolean Whether double quotes should be escaped

setEscapeGtLt() 공개 메소드

If true, greater than will be escaped as "\u003E" and less than as "\u003C". By default, greater than/less than symbols are not escaped.
public setEscapeGtLt ( boolean $enabled )
$enabled boolean Whether greater than/less than should be escaped

setEscapeSingleQuote() 공개 메소드

If true, single quotes will be escaped as "\u0027". By default, single quotes are not escaped.
public setEscapeSingleQuote ( boolean $enabled )
$enabled boolean Whether single quotes should be escaped

setEscapeSlash() 공개 메소드

If true, forward slashes will be escaped as "\/". By default, forward slashes are not escaped.
public setEscapeSlash ( boolean $enabled )
$enabled boolean Whether forward slashes should be escaped

setEscapeUnicode() 공개 메소드

If true, unicode characters will be escaped as hexadecimals strings. For example, "ü" will be escaped as "\u00fc". By default, unicode characters are escaped.
public setEscapeUnicode ( boolean $enabled )
$enabled boolean Whether unicode characters should be escaped

setMaxDepth() 공개 메소드

If the depth is exceeded during encoding, an {@link EncodingFailedException} will be thrown. A depth of zero means that objects are not allowed. A depth of one means only one level of objects or arrays is allowed.
public setMaxDepth ( integer $maxDepth )
$maxDepth integer The maximum recursion depth

setNumericEncoding() 공개 메소드

By default, non-associative arrays are decoded as JSON strings.
public setNumericEncoding ( integer $encoding )
$encoding integer One of the constants {@link JSON_STRING} and {@link JSON_NUMBER}

setPrettyPrinting() 공개 메소드

If true, line breaks will be added after object properties and array entries. Each new nesting level will be indented by four spaces. By default, pretty printing is not enabled.
public setPrettyPrinting ( boolean $prettyPrinting )
$prettyPrinting boolean Whether JSON strings should be formatted

setTerminateWithLineFeed() 공개 메소드

By default, JSON strings are not terminated with a line feed.
public setTerminateWithLineFeed ( boolean $enabled )
$enabled boolean Whether JSON strings should be terminated with a line feed