src/XQueue/Maileon/API/JSON/JSONDeserializer.php
private static function fromArray($object, $type = null, $innerType = null) {
        if($type == 'array') {
            foreach ($object as $element) {
                // call this method on each element
                $result[]= self::fromArray($element, $innerType);
            }
            
            // return the processed array
            return $result;
        } else if (class_exists($type)) {
            // create the class we are deserializing
            $class = new $type();
            
            // if we can call fromArray on the class call it, otherwise
            // return the object as-is and trigger a warning
            if(is_subclass_of($class, 'AbstractJSONWrapper')) {
                $class->fromArray($object);
                return $class;
            } else {
                trigger_error( __CLASS__ . ": Trying to deserialize " . get_class($class)); 
                return $object;
            }
        } else {
            // if this is not a class, we have nothing to do
            return $object;
        }
    }
private static function fromArray($object, $type = null, $innerType = null) {
        if($type == 'array') {
            foreach ($object as $element) {
                // call this method on each element
                $result[]= self::fromArray($element, $innerType);
            }
            
            // return the processed array
            return $result;
        } else if (class_exists($type)) {
            // create the class we are deserializing
            $class = new $type();
            
            // if we can call fromArray on the class call it, otherwise
            // return the object as-is and trigger a warning
            if(is_subclass_of($class, 'AbstractJSONWrapper')) {
                $class->fromArray($object);
                return $class;
            } else {
                trigger_error( __CLASS__ . ": Trying to deserialize " . get_class($class)); 
                return $object;
            }
        } else {
            // if this is not a class, we have nothing to do
            return $object;
        }
    }
Helper function used to build this class from an array.

@param array $object
The result of json_decode
@param string $type
The name of the type
@param string $innerType
The name of the inner type
@return array|AbstractJSONWrapper
The parsed object