API Documentation

Json/Encoder.php

Classes 
category
Zend
copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
Zend_Json
version
$Id: Encoder.php 22453 2010-06-18 18:17:52Z ralph $
Classes
Zend_Json_Encoder

Description

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.

Zend_Json_Encoder

category
Zend
copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
Zend_Json
Properties
$_cycleCheck
$_options
$_visited
Methods
__construct
encode
_encodeValue
_encodeObject
_wasVisited
_encodeArray
_encodeDatum
_encodeString
_encodeConstants
_encodeMethods
_encodeVariables
encodeClass
encodeClasses
encodeUnicodeString
_utf82utf16

Description

Encode PHP constructs to JSON

Properties

$_cycleCheck

boolean $_cycleCheck = ''

Whether or not to check for possible cycling

Details

$_cycleCheck
boolean
visibility
protected
default
final
false
static
false

$_options

array $_options = 'array'

Additional options used during encoding

Details

$_options
array
visibility
protected
default
array
final
false
static
false

$_visited

array $_visited = 'array'

Array of visited objects; used to prevent cycling.

Details

$_visited
array
visibility
protected
default
array
final
false
static
false

Methods

__construct

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

Constructor

Arguments
$cycleCheck
boolean
Whether or not to check for recursion when encoding
$options
array
Additional options used during encoding
Details
visibility
protected
final
false
static
false

_encodeArray

_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.

Arguments
$array
$array
array
Output
string
Details
visibility
protected
final
false
static
false

_encodeConstants

_encodeConstants( $cls $cls ) : string

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

Arguments
$cls
$cls
ReflectionClass
Output
string
Encoded constant block in class2 format
Details
visibility
private
final
false
static
true

_encodeDatum

_encodeDatum( $value $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.

Arguments
$value
$value
mixed
Output
string
Details
visibility
protected
final
false
static
false

_encodeMethods

_encodeMethods( $cls $cls ) : string

Encode the public methods of the ReflectionClass in the class2 format

Arguments
$cls
$cls
ReflectionClass
Output
string
Encoded method fragment
Details
visibility
private
final
false
static
true

_encodeObject

_encodeObject( $value $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.

Arguments
$value
$value
object
Output
string
Details
visibility
protected
final
false
static
false
throws
If recursive checks are enabled and the object has been serialized previously

_encodeString

_encodeString( $value $string ) : string

JSON encode a string value by escaping characters as necessary

Arguments
$string
$value
string
Output
string
Details
visibility
protected
final
false
static
false

_encodeValue

_encodeValue( $value $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()})

Arguments
$value
$value
mixed The value to be encoded
Output
string
Encoded value
Details
visibility
protected
final
false
static
false

_encodeVariables

_encodeVariables( $cls $cls ) : string

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

Arguments
$cls
$cls
ReflectionClass
Output
string
Encode properties list
Details
visibility
private
final
false
static
true

_utf82utf16

_utf82utf16( string $utf8 ) : string

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

Arguments
$utf8
string
UTF-8 character
Output
string
UTF-16 character
Details
visibility
protected
final
false
static
true
link
http://solarphp.com

_wasVisited

_wasVisited( mixed $value ) : boolean

Determine if an object has been serialized already

Arguments
$value
mixed
Output
boolean
Details
visibility
protected
final
false
static
false

encode

encode( mixed $value, boolean $cycleCheck = false, array $options = array ) : string

Use the JSON encoding scheme for the value specified

Arguments
$value
mixed
The value to be encoded
$cycleCheck
boolean
Whether or not to check for possible object recursion when encoding
$options
array
Additional options used during encoding
Output
string
The encoded value
Details
visibility
public
final
false
static
true

encodeClass

encodeClass( $className $className, $package $package ) : string

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

Arguments
$className
$className
string The name of the class, the class must be instantiable using a null constructor
$package
$package
string Optional package name appended to JavaScript proxy class name
Output
string
The class2 (JavaScript) encoding of the class
Details
visibility
public
final
false
static
true
throws

encodeClasses

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

Encode several classes at once

Returns JSON encoded classes, using {@link encodeClass()}.

Arguments
$classNames
array
$package
string
Output
string
Details
visibility
public
final
false
static
true

encodeUnicodeString

encodeUnicodeString( string $value ) : string

Encode Unicode Characters to \u0000 ASCII syntax.

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

Arguments
$value
string
Output
string
Details
visibility
public
final
false
static
true
link
http://solarphp.com/
link
http://svn.solarphp.com/core/trunk/Solar/Json.php
Documentation was generated by DocBlox.