Zend Framework  2.4
Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Decoder Class Reference

Decode JSON encoded string to PHP variable constructs. More...

Static Public Member Functions

static decodeUnicodeString ($chrs)
 Decode Unicode Characters from ASCII syntax.
 
static decode ($source, $objectDecodeType=Json::TYPE_OBJECT)
 Decode a JSON source string.
 

Public Attributes

const EOF = 0
 Parse tokens used to decode the JSON object.
 
const DATUM = 1
 
const LBRACE = 2
 
const LBRACKET = 3
 
const RBRACE = 4
 
const RBRACKET = 5
 
const COMMA = 6
 
const COLON = 7
 

Protected Member Functions

 __construct ($source, $decodeType)
 Constructor.
 
 _decodeValue ()
 Recursive driving routine for supported toplevel tops.
 
 _decodeObject ()
 Decodes an object of the form: { "attribute: value, "attribute2" : value,...}.
 
 _decodeArray ()
 Decodes a JSON array format: [element, element2,...,elementN].
 
 _eatWhitespace ()
 Removes whitespace characters from the source input.
 
 _getNextToken ()
 Retrieves the next token from the source stream.
 

Static Protected Member Functions

static _utf162utf8 ($utf16)
 Convert a string from one UTF-16 char to one UTF-8 char.
 

Protected Attributes

 $source
 
 $sourceLength
 
 $offset
 
 $token
 
 $decodeType
 
 $tokenValue
 

Detailed Description

Decode JSON encoded string to PHP variable constructs.

Constructor & Destructor Documentation

__construct (   $source,
  $decodeType 
)
protected

Constructor.

Parameters
string$sourceString source to decode
int$decodeTypeHow objects should be decoded – see ::TYPE_ARRAY and ::TYPE_OBJECT for valid values
Exceptions
InvalidArgumentException

Member Function Documentation

_decodeArray ( )
protected

Decodes a JSON array format: [element, element2,...,elementN].

Returns
array
Exceptions
RuntimeException
_decodeObject ( )
protected

Decodes an object of the form: { "attribute: value, "attribute2" : value,...}.

If Zend was used to encode the original object then a special attribute called __className which specifies a class name that should wrap the data contained within the encoded source.

Decodes to either an array or stdClass object, based on the value of $decodeType. If invalid $decodeType present, returns as an array.

Returns
array|stdClass
Exceptions
RuntimeException
_decodeValue ( )
protected

Recursive driving routine for supported toplevel tops.

Returns
mixed
_eatWhitespace ( )
protected

Removes whitespace characters from the source input.

_getNextToken ( )
protected

Retrieves the next token from the source stream.

Returns
int Token constant value specified in class definition
Exceptions
RuntimeException
static _utf162utf8 (   $utf16)
staticprotected

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

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

string $utf16 UTF-16 character string UTF-8 character

static decode (   $source,
  $objectDecodeType = Json::TYPE_OBJECT 
)
static

Decode a JSON source string.

Decodes a JSON encoded string. The value returned will be one of the following:

  • integer
  • float
  • boolean
  • null

stdClass

  • array
    • array of one or more of the above types

By default, decoded objects will be returned as associative arrays; to return a stdClass object instead, pass ::TYPE_OBJECT to the $objectDecodeType parameter.

public

Parameters
string$sourceString to be decoded
int$objectDecodeTypeHow objects should be decoded; should be either or ::TYPE_ARRAY or ::TYPE_OBJECT; defaults to TYPE_ARRAY
Returns
mixed
static decodeUnicodeString (   $chrs)
static

Decode Unicode Characters from ASCII syntax.

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

https://github.com/solarphp/core/blob/master/Solar/Json.php string $chrs string

Member Data Documentation

$decodeType
protected
$offset
protected
$source
protected
$sourceLength
protected
$token
protected
$tokenValue
protected
const COLON = 7
const COMMA = 6
const DATUM = 1
const EOF = 0

Parse tokens used to decode the JSON object.

These are not for public consumption, they are just used internally to the class.

const LBRACE = 2
const LBRACKET = 3
const RBRACE = 4
const RBRACKET = 5