/** * Check & Replace Zend_Json_Expr for tmp ids in the valueToEncode * * Check if the value is a Zend_Json_Expr, and if replace its value * with a magic key and save the javascript expression in an array. * * NOTE this method is recursive. * * NOTE: This method is used internally by the encode method. * * @see encode * @param mixed $valueToCheck a string - object property to be encoded * @return void */ protected static function _recursiveJsonExprFinder(&$value, array &$javascriptExpressions, $currentKey = null) { if ($value instanceof Expr) { // TODO: Optimize with ascii keys, if performance is bad $magicKey = "____" . $currentKey . "_" . count($javascriptExpressions); $javascriptExpressions[] = array("magicKey" => is_int($currentKey) ? $magicKey : Encoder::encodeUnicodeString($magicKey), "value" => $value->__toString()); $value = $magicKey; } elseif (is_array($value)) { foreach ($value as $k => $v) { $value[$k] = self::_recursiveJsonExprFinder($value[$k], $javascriptExpressions, $k); } } elseif (is_object($value)) { foreach ($value as $k => $v) { $value->{$k} = self::_recursiveJsonExprFinder($value->{$k}, $javascriptExpressions, $k); } } return $value; }