本文整理汇总了PHP中Nette\Reflection\ClassType::newInstanceWithoutConstructor方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassType::newInstanceWithoutConstructor方法的具体用法?PHP ClassType::newInstanceWithoutConstructor怎么用?PHP ClassType::newInstanceWithoutConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Reflection\ClassType
的用法示例。
在下文中一共展示了ClassType::newInstanceWithoutConstructor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertToTyped
/**
* 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;
}