Json/Encoder.php

Show: PublicProtectedPrivateinherited
Table of Contents
Zend Framework
LICENSE This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Json  
Version
$Id$  

\Zend_Json_Encoder

Package: Zend_Json
Encode PHP constructs to JSON
Category
Zend  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Properties

>VPropertyprotectedboolean $_cycleCheck
Whether or not to check for possible cycling
Details
Type
boolean
>VPropertyprotectedarray $_options = array()
Additional options used during encoding
Default valuearray()Details
Type
array
>VPropertyprotectedarray $_visited = array()
Array of visited objects; used to prevent cycling.
Default valuearray()Details
Type
array

Methods

methodprotected__construct(boolean $cycleCheck = false, array $options = array()) : void

Constructor

Parameters
NameTypeDescription
$cycleCheckboolean

Whether or not to check for recursion when encoding

$optionsarray

Additional options used during encoding

methodprotected_encodeArray(\array& $array) : string

JSON encode an array value

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
NameTypeDescription
$array\array&
Returns
TypeDescription
string
methodprivate_encodeConstants(\ReflectionClass $cls) : string
static

Encode the constants associated with the ReflectionClass parameter. The encoding format is based on the class2 format

Parameters
NameTypeDescription
$cls\ReflectionClass
Returns
TypeDescription
stringEncoded constant block in class2 format
methodprotected_encodeDatum(\mixed& $value) : string

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

If value type is not a string, number, boolean, or null, the string 'null' is returned.
Parameters
NameTypeDescription
$value\mixed&
Returns
TypeDescription
string
methodprivate_encodeMethods(\ReflectionClass $cls) : string
static

Encode the public methods of the ReflectionClass in the class2 format

Parameters
NameTypeDescription
$cls\ReflectionClass
Returns
TypeDescription
stringEncoded method fragment
methodprotected_encodeObject(object $value) : string

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

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
NameTypeDescription
$valueobject
Returns
TypeDescription
string
Throws
ExceptionDescription
\Zend_Json_ExceptionIf recursive checks are enabled and the object has been serialized previously
methodprotected_encodeString( $string) : string

JSON encode a string value by escaping characters as necessary

Parameters
NameTypeDescription
$string
Returns
TypeDescription
string
methodprotected_encodeValue(mixed $value) : string

Recursive driver which determines the type of value to be encoded and then dispatches to the appropriate method. $values are either - objects (returns from {@link _encodeObject()}) - arrays (returns from {@link _encodeArray()}) - basic datums (e.g. numbers or strings) (returns from {@link _encodeDatum()})

Parameters
NameTypeDescription
$valuemixed

The value to be encoded

Returns
TypeDescription
stringEncoded value
methodprivate_encodeVariables(\ReflectionClass $cls) : string
static

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

Parameters
NameTypeDescription
$cls\ReflectionClass
Returns
TypeDescription
stringEncode properties list
methodprotected_utf82utf16(string $utf8) : string
static

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

Normally should be handled by mb_convert_encoding, but provides a slower PHP-only method for installations that lack the multibye string extension. This method is from the Solar Framework by Paul M. Jones
Parameters
NameTypeDescription
$utf8string

UTF-8 character

Returns
TypeDescription
stringUTF-16 character
Details
Link
http://solarphp.com  
methodprotected_wasVisited(mixed $value) : boolean

Determine if an object has been serialized already

Parameters
NameTypeDescription
$valuemixed
Returns
TypeDescription
boolean
methodpublicencode(mixed $value, boolean $cycleCheck = false, array $options = array()) : string
static

Use the JSON encoding scheme for the value specified

Parameters
NameTypeDescription
$valuemixed

The value to be encoded

$cycleCheckboolean

Whether or not to check for possible object recursion when encoding

$optionsarray

Additional options used during encoding

Returns
TypeDescription
stringThe encoded value
methodpublicencodeClass(string $className, string $package = '') : string
static

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

NOTE: Currently only public methods and variables are proxied onto the client machine
Parameters
NameTypeDescription
$classNamestring

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

$packagestring

Optional package name appended to JavaScript proxy class name

Returns
TypeDescription
stringThe class2 (JavaScript) encoding of the class
Throws
ExceptionDescription
\Zend_Json_Exception
methodpublicencodeClasses(array $classNames, string $package = '') : string
static

Encode several classes at once

Returns JSON encoded classes, using {@link encodeClass()}.
Parameters
NameTypeDescription
$classNamesarray
$packagestring
Returns
TypeDescription
string
methodpublicencodeUnicodeString(string $value) : string
static

Encode Unicode Characters to \u0000 ASCII syntax.

This algorithm was originally developed for the Solar Framework by Paul M. Jones
Parameters
NameTypeDescription
$valuestring
Returns
TypeDescription
string
Details
Link
http://solarphp.com/  
Link
http://svn.solarphp.com/core/trunk/Solar/Json.php  
Documentation was generated by phpDocumentor 2.2.0 .