/** * if the object contains an explicit type marker, this method attempts to convert it to its typed counterpart * if the typed class is already available, then simply creates a new instance of it. If not, * attempts to load the file from the available service folders. * If then the class is still not available, the object is not converted * note: This is not a recursive function. Rather the recusrion is handled by Amfphp_Core_Amf_Util::applyFunctionToContainedObjects. * must be public so that Amfphp_Core_Amf_Util::applyFunctionToContainedObjects can call it * * Part of AMFPHP * @author Silex Labs * * @param mixed $obj * @throws \Goodshape\InvalidStateException * @return mixed */ private function convertToTyped($obj) { if (!is_object($obj)) { return $obj; } $explicitTypeField = Deserializer::FIELD_EXPLICIT_TYPE; if (isset($obj->{$explicitTypeField})) { $customClassName = $obj->{$explicitTypeField}; foreach ($this->customClassesNamespaces as $namespace) { $fqcn = $namespace . '\\' . $customClassName; if (class_exists($fqcn)) { //class is available. Use it! $classReflection = new ClassType($fqcn); $typedObj = $classReflection->newInstanceWithoutConstructor(); foreach ($obj as $key => $data) { // loop over each element to copy it into typed object if ($key != $explicitTypeField) { $typedObj->{$key} = $data; } } return $typedObj; } } throw new InvalidStateException("Class {$customClassName} was not found in any of provided namespaces."); } return $obj; }