Definition at line 30 of file Encoder.php.
◆ __construct()
__construct |
( |
|
$cycleCheck = false , |
|
|
|
$options = array() |
|
) |
| |
|
protected |
Constructor
- Parameters
-
boolean | $cycleCheck | Whether or not to check for recursion when encoding |
array | $options | Additional options used during encoding |
- Returns
- void
Definition at line 60 of file Encoder.php.
62 $this->_cycleCheck = $cycleCheck;
◆ _encodeArray()
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
-
- Returns
- string
Definition at line 192 of file Encoder.php.
197 if (!empty($array) && (array_keys($array) !== range(0, count($array) - 1))) {
200 foreach ($array as $key =>
$value) {
201 $key = (string) $key;
206 $result .= implode(
',', $tmpArray);
211 $length = count($array);
212 for (
$i = 0;
$i < $length;
$i++) {
215 $result .= implode(
',', $tmpArray);
◆ _encodeDatum()
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
-
- Returns
- string
Definition at line 232 of file Encoder.php.
elseif(isset( $params[ 'redirect_parent']))
◆ _encodeObject()
_encodeObject |
( |
& |
$value | ) |
|
|
protected |
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
-
- Returns
- string
- Exceptions
-
Zend_Json_Exception | If recursive checks are enabled and the object has been serialized previously |
Definition at line 114 of file Encoder.php.
116 if ($this->_cycleCheck) {
119 if (isset($this->_options[
'silenceCyclicalExceptions'])
120 && $this->_options[
'silenceCyclicalExceptions']===
true) {
122 return '"* RECURSION (' . get_class(
$value) .
') *"';
125 #require_once 'Zend/Json/Exception.php'; 127 'Cycles not supported in JSON encoding, cycle introduced by ' 128 .
'class "' . get_class(
$value) .
'"' 133 $this->_visited[] =
$value;
137 if (method_exists(
$value,
'toJson')) {
138 $props =
',' . preg_replace(
"/^\{(.*)\}$/",
"\\1",
$value->toJson());
140 if (
$value instanceof IteratorAggregate) {
141 $propCollection =
$value->getIterator();
145 $propCollection = get_object_vars(
$value);
148 foreach ($propCollection as
$name => $propValue) {
149 if (isset($propValue)) {
elseif(isset( $params[ 'redirect_parent']))
if(!isset($_GET['name'])) $name
◆ _encodeString()
_encodeString |
( |
& |
$string | ) |
|
|
protected |
JSON encode a string value by escaping characters as necessary
- Parameters
-
- Returns
- string
Definition at line 255 of file Encoder.php.
259 $search = array(
'\\',
"\n",
"\t",
"\r",
"\b",
"\f",
'"',
'/');
260 $replace = array(
'\\\\',
'\\n',
'\\t',
'\\r',
'\\b',
'\\f',
'\"',
'\\/');
261 $string = str_replace($search, $replace, $string);
266 $string = str_replace(array(chr(0x08), chr(0x0C)), array(
'\b',
'\f'), $string);
269 return '"' . $string .
'"';
static encodeUnicodeString($value)
◆ _encodeValue()
Recursive driver which determines the type of value to be encoded and then dispatches to the appropriate method. $values are either
- Parameters
-
mixed | $value | The value to be encoded |
- Returns
- string Encoded value
Definition at line 90 of file Encoder.php.
94 }
else if (is_array(
$value)) {
◆ _utf82utf16()
static _utf82utf16 |
( |
|
$utf8 | ) |
|
|
staticprotected |
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
string $utf8 UTF-8 character string UTF-16 character
Definition at line 545 of file Encoder.php.
549 return mb_convert_encoding($utf8,
'UTF-16',
'UTF-8');
552 switch (strlen($utf8)) {
561 return chr(0x07 & (ord($utf8{0}) >> 2))
562 . chr((0xC0 & (ord($utf8{0}) << 6))
563 | (0x3F & ord($utf8{1})));
568 return chr((0xF0 & (ord($utf8{0}) << 4))
569 | (0x0F & (ord($utf8{1}) >> 2)))
570 . chr((0xC0 & (ord($utf8{1}) << 6))
571 | (0x7F & ord($utf8{2})));
◆ _wasVisited()
Determine if an object has been serialized already
- Parameters
-
- Returns
- boolean
Definition at line 169 of file Encoder.php.
171 if (in_array(
$value, $this->_visited,
true)) {
◆ encode()
static encode |
( |
|
$value, |
|
|
|
$cycleCheck = false , |
|
|
|
$options = array() |
|
) |
| |
|
static |
Use the JSON encoding scheme for the value specified
- Parameters
-
mixed | $value | The value to be encoded |
boolean | $cycleCheck | Whether or not to check for possible object recursion when encoding |
array | $options | Additional options used during encoding |
- Returns
- string The encoded value
Definition at line 74 of file Encoder.php.
76 $encoder =
new self(($cycleCheck) ?
true :
false,
$options);
77 return $encoder->_encodeValue(
$value);
◆ encodeClass()
static encodeClass |
( |
|
$className, |
|
|
|
$package = '' |
|
) |
| |
|
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
-
string | $className | The name of the class, the class must be instantiable using a null constructor |
string | $package | Optional package name appended to JavaScript proxy class name |
- Returns
- string The class2 (JavaScript) encoding of the class
- Exceptions
-
Definition at line 405 of file Encoder.php.
408 if (! $cls->isInstantiable()) {
409 #require_once 'Zend/Json/Exception.php'; 413 return "Class.create('$package$className',{" 414 . self::_encodeConstants($cls) .
"," 415 . self::_encodeMethods($cls) .
"," 416 . self::_encodeVariables($cls) .
'});';
◆ encodeClasses()
static encodeClasses |
( |
array |
$classNames, |
|
|
|
$package = '' |
|
) |
| |
|
static |
Encode several classes at once
Returns JSON encoded classes, using encodeClass().
- Parameters
-
array | $classNames | |
string | $package | |
- Returns
- string
Definition at line 429 of file Encoder.php.
static encodeClass($className, $package='')
◆ encodeUnicodeString()
static encodeUnicodeString |
( |
|
$value | ) |
|
|
static |
Encode Unicode Characters to \u0000 ASCII syntax.
This algorithm was originally developed for the Solar Framework by Paul M. Jones
http://svn.solarphp.com/core/trunk/Solar/Json.php string $value string
Iterate over every character in the string, escaping with a slash or encoding to UTF-8 where necessary
Definition at line 450 of file Encoder.php.
452 $strlen_var = strlen(
$value);
459 for(
$i = 0;
$i < $strlen_var;
$i++) {
463 case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
468 case (($ord_var_c & 0xE0) == 0xC0):
471 $char = pack(
'C*', $ord_var_c, ord(
$value[
$i + 1]));
474 $ascii .= sprintf(
'\u%04s', bin2hex($utf16));
477 case (($ord_var_c & 0xF0) == 0xE0):
480 $char = pack(
'C*', $ord_var_c,
485 $ascii .= sprintf(
'\u%04s', bin2hex($utf16));
488 case (($ord_var_c & 0xF8) == 0xF0):
491 $char = pack(
'C*', $ord_var_c,
497 $ascii .= sprintf(
'\u%04s', bin2hex($utf16));
500 case (($ord_var_c & 0xFC) == 0xF8):
503 $char = pack(
'C*', $ord_var_c,
510 $ascii .= sprintf(
'\u%04s', bin2hex($utf16));
513 case (($ord_var_c & 0xFE) == 0xFC):
516 $char = pack(
'C*', $ord_var_c,
524 $ascii .= sprintf(
'\u%04s', bin2hex($utf16));
static _utf82utf16($utf8)
◆ $_cycleCheck
◆ $_options
◆ $_visited
The documentation for this class was generated from the following file:
- vendor/magento/zendframework1/library/Zend/Json/Encoder.php