PHP Класс Webmozart\Json\JsonEncoder

С версии: 1.0
Автор: Bernhard Schussek ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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