当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassType::newInstanceWithoutConstructor方法代码示例

本文整理汇总了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;
 }
开发者ID:goodshape,项目名称:nette-amf,代码行数:42,代码来源:CustomClassConvertor.php


注:本文中的Nette\Reflection\ClassType::newInstanceWithoutConstructor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。