Encode PHP constructs to JSON

category Zend
package Zend_Json

 Methods

Use the JSON encoding scheme for the value specified

encode(mixed $value, bool $cycleCheck, array $options) : string

Parameters

$value

mixed

The value to be encoded

$cycleCheck

bool

Whether or not to check for possible object recursion when encoding

$options

array

Additional options used during encoding

Returns

stringThe encoded value

Encodes the given $className into the class2 model of encoding PHP classes into JavaScript class2 classes.

encodeClass(\Zend\Json\$className $className, \Zend\Json\$package $package) : string

NOTE: Currently only public methods and variables are proxied onto the client machine

Parameters

$className

\Zend\Json\$className

string The name of the class, the class must be instantiable using a null constructor

$package

\Zend\Json\$package

string Optional package name appended to JavaScript proxy class name

Exceptions

\Zend\Json\Exception\InvalidArgumentException

Returns

stringThe class2 (JavaScript) encoding of the class

Encode several classes at once

encodeClasses(array $classNames, string $package) : string

Returns JSON encoded classes, using encodeClass().

Parameters

$classNames

array

$package

string

Returns

string

Encode Unicode Characters to \u0000 ASCII syntax.

encodeUnicodeString(string $value) : string

This algorithm was originally developed for the Solar Framework by Paul M. Jones

link http://solarphp.com/
link http://svn.solarphp.com/core/trunk/Solar/JSON.php

Parameters

$value

string

Returns

string

Constructor

__construct(bool $cycleCheck, array $options) : \Zend\Json\Encoder

Parameters

$cycleCheck

bool

Whether or not to check for recursion when encoding

$options

array

Additional options used during encoding

Returns

JSON encode an array value

_encodeArray(\Zend\Json\$array $array) : string

Recursively encodes each value of an array and returns a JSON encoded array string.

Arrays are defined as integer-indexed arrays starting at index 0, where the last index is (count($array) -1); any deviation from that is considered an associative array, and will be encoded as such.

Parameters

$array

\Zend\Json\$array

array

Returns

string

JSON encode a basic data type (string, number, boolean, null)

_encodeDatum(mixed $value) : string

If value type is not a string, number, boolean, or null, the string 'null' is returned.

Parameters

$value

mixed

Returns

string

Encode an object to JSON by encoding each of the public properties

_encodeObject(\Zend\Json\$value $value) : string

A special property is added to the JSON object called '__className' that contains the name of the class of $value. This is used to decode the object on the client into a specific class.

Parameters

$value

\Zend\Json\$value

object

Exceptions

\Zend\Json\Exception\RecursionException If recursive checks are enabled and the object has been serialized previously

Returns

string

JSON encode a string value by escaping characters as necessary

_encodeString(string $string) : string

Parameters

$string

string

Returns

string

Recursive driver which determines the type of value to be encoded and then dispatches to the appropriate method.

_encodeValue(\Zend\Json\$value $value) : string

$values are either - objects (returns from _encodeObject()) - arrays (returns from _encodeArray()) - basic datums (e.g. numbers or strings) (returns from _encodeDatum())

Parameters

$value

\Zend\Json\$value

mixed The value to be encoded

Returns

stringEncoded value

Convert a string from one UTF-8 char to one UTF-16 char.

_utf82utf16(string $utf8) : string

Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibyte string extension.

This method is from the Solar Framework by Paul M. Jones

link http://solarphp.com

Parameters

$utf8

string

UTF-8 character

Returns

stringUTF-16 character

Determine if an object has been serialized already

_wasVisited(mixed $value) : bool

Parameters

$value

mixed

Returns

bool

Encode the constants associated with the ReflectionClass parameter.

_encodeConstants(\ReflectionClass $cls) : string

The encoding format is based on the class2 format

Parameters

Returns

stringEncoded constant block in class2 format

Encode the public methods of the ReflectionClass in the class2 format

_encodeMethods(\ReflectionClass $cls) : string

Parameters

Returns

stringEncoded method fragment

Encode the public properties of the ReflectionClass in the class2 format.

_encodeVariables(\ReflectionClass $cls) : string

Parameters

Returns

stringEncode properties list

 Properties

 

Whether or not to check for possible cycling

$cycleCheck : bool

 

Additional options used during encoding

$options : array

 

Array of visited objects; used to prevent cycling.

$visited : array