diff -r 5e7a0fedabdf -r 877f952ae2bd web/lib/Zend/Json/Encoder.php --- a/web/lib/Zend/Json/Encoder.php Thu Mar 21 17:31:31 2013 +0100 +++ b/web/lib/Zend/Json/Encoder.php Thu Mar 21 19:50:53 2013 +0100 @@ -14,9 +14,9 @@ * * @category Zend * @package Zend_Json - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: Encoder.php 22452 2010-06-18 18:13:23Z ralph $ + * @version $Id: Encoder.php 25059 2012-11-02 21:01:06Z rob $ */ /** @@ -24,7 +24,7 @@ * * @category Zend * @package Zend_Json - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Json_Encoder @@ -74,7 +74,6 @@ public static function encode($value, $cycleCheck = false, $options = array()) { $encoder = new self(($cycleCheck) ? true : false, $options); - return $encoder->_encodeValue($value); } @@ -85,7 +84,7 @@ * - arrays (returns from {@link _encodeArray()}) * - basic datums (e.g. numbers or strings) (returns from {@link _encodeDatum()}) * - * @param $value mixed The value to be encoded + * @param mixed $value The value to be encoded * @return string Encoded value */ protected function _encodeValue(&$value) @@ -108,7 +107,7 @@ * that contains the name of the class of $value. This is used to decode * the object on the client into a specific class. * - * @param $value object + * @param object $value * @return string * @throws Zend_Json_Exception If recursive checks are enabled and the object has been serialized previously */ @@ -135,23 +134,28 @@ } $props = ''; - - if ($value instanceof Iterator) { - $propCollection = $value; + if (method_exists($value, 'toJson')) { + $props =',' . preg_replace("/^\{(.*)\}$/","\\1",$value->toJson()); } else { - $propCollection = get_object_vars($value); - } + if ($value instanceof IteratorAggregate) { + $propCollection = $value->getIterator(); + } elseif ($value instanceof Iterator) { + $propCollection = $value; + } else { + $propCollection = get_object_vars($value); + } - foreach ($propCollection as $name => $propValue) { - if (isset($propValue)) { - $props .= ',' - . $this->_encodeString($name) - . ':' - . $this->_encodeValue($propValue); + foreach ($propCollection as $name => $propValue) { + if (isset($propValue)) { + $props .= ',' + . $this->_encodeString($name) + . ':' + . $this->_encodeValue($propValue); + } } } - - return '{"__className":"' . get_class($value) . '"' + $className = get_class($value); + return '{"__className":' . $this->_encodeString($className) . $props . '}'; } @@ -182,7 +186,7 @@ * the last index is (count($array) -1); any deviation from that is * considered an associative array, and will be encoded as such. * - * @param $array array + * @param array& $array * @return string */ protected function _encodeArray(&$array) @@ -222,7 +226,7 @@ * If value type is not a string, number, boolean, or null, the string * 'null' is returned. * - * @param $value mixed + * @param mixed& $value * @return string */ protected function _encodeDatum(&$value) @@ -245,7 +249,7 @@ /** * JSON encode a string value by escaping characters as necessary * - * @param $value string + * @param string& $value * @return string */ protected function _encodeString(&$string) @@ -270,7 +274,7 @@ * Encode the constants associated with the ReflectionClass * parameter. The encoding format is based on the class2 format * - * @param $cls ReflectionClass + * @param ReflectionClass $cls * @return string Encoded constant block in class2 format */ private static function _encodeConstants(ReflectionClass $cls) @@ -295,7 +299,7 @@ * Encode the public methods of the ReflectionClass in the * class2 format * - * @param $cls ReflectionClass + * @param ReflectionClass $cls * @return string Encoded method fragment * */ @@ -359,7 +363,7 @@ * Encode the public properties of the ReflectionClass in the class2 * format. * - * @param $cls ReflectionClass + * @param ReflectionClass $cls * @return string Encode properties list * */ @@ -391,10 +395,10 @@ * NOTE: Currently only public methods and variables are proxied onto * the client machine * - * @param $className string The name of the class, the class must be - * instantiable using a null constructor - * @param $package string Optional package name appended to JavaScript - * proxy class name + * @param string $className The name of the class, the class must be + * instantiable using a null constructor + * @param string $package Optional package name appended to JavaScript + * proxy class name * @return string The class2 (JavaScript) encoding of the class * @throws Zend_Json_Exception */