62 $this->_cycleCheck = $cycleCheck;
76 $encoder =
new self(($cycleCheck) ?
true :
false,
$options);
77 return $encoder->_encodeValue(
$value);
94 }
else if (is_array(
$value)) {
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)) {
171 if (in_array(
$value, $this->_visited,
true)) {
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);
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 .
'"';
280 private static function _encodeConstants(ReflectionClass $cls)
283 $constants = $cls->getConstants();
286 if (!empty($constants)) {
287 foreach ($constants as $key =>
$value) {
291 $result .= implode(
', ', $tmpArray);
306 private static function _encodeMethods(ReflectionClass $cls)
324 if (
'__construct' !=
$method->getName()) {
325 $parameters =
$method->getParameters();
326 $paramCount = count($parameters);
327 $argsStarted =
false;
329 $argNames =
"var argNames=[";
330 foreach ($parameters as $param) {
341 $argNames .=
'"' . $param->getName() .
'"';
349 .
'var result = ZAjaxEngine.invokeRemoteMethod(' 350 .
"this, '" .
$method->getName()
351 .
"',argNames,arguments);" 352 .
'return(result);}';
370 private static function _encodeVariables(ReflectionClass $cls)
373 $propValues = get_class_vars($cls->getName());
379 if (! $prop->isPublic()) {
383 $tmpArray[] = $prop->getName()
387 $result .= implode(
',', $tmpArray);
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) .
'});';
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));
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})));
elseif(isset( $params[ 'redirect_parent']))
static encodeUnicodeString($value)
static encodeClasses(array $classNames, $package='')
__construct($cycleCheck=false, $options=array())
static _utf82utf16($utf8)
static encodeClass($className, $package='')
static encode($value, $cycleCheck=false, $options=array())
if(!isset($_GET['name'])) $name