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


PHP ReflectionClass::newInstance方法代码示例

本文整理汇总了PHP中ReflectionClass::newInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::newInstance方法的具体用法?PHP ReflectionClass::newInstance怎么用?PHP ReflectionClass::newInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionClass的用法示例。


在下文中一共展示了ReflectionClass::newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 public function load()
 {
     $files = $this->_getFiles();
     $manifestRegistry = ZendL_Tool_Rpc_Manifest_Registry::getInstance();
     $providerRegistry = ZendL_Tool_Rpc_Provider_Registry::getInstance();
     $classesLoadedBefore = get_declared_classes();
     $oldLevel = error_reporting(E_ALL | ~E_STRICT);
     // remove strict so that other packages wont throw warnings
     foreach ($files as $file) {
         require_once $file;
     }
     error_reporting($oldLevel);
     // restore old error level
     $classesLoadedAfter = get_declared_classes();
     $loadedClasses = array_diff($classesLoadedAfter, $classesLoadedBefore);
     foreach ($loadedClasses as $loadedClass) {
         $reflectionClass = new ReflectionClass($loadedClass);
         if ($reflectionClass->implementsInterface('ZendL_Tool_Rpc_Manifest_Interface') && !$reflectionClass->isAbstract()) {
             $manifestRegistry->addManifest($reflectionClass->newInstance());
         }
         if ($reflectionClass->implementsInterface('ZendL_Tool_Rpc_Provider_Interface') && !$reflectionClass->isAbstract()) {
             $providerRegistry->addProvider($reflectionClass->newInstance());
         }
     }
 }
开发者ID:lortnus,项目名称:zf1,代码行数:25,代码来源:Abstract.php

示例2: createEntity

 /**
  * @return object
  */
 protected function createEntity()
 {
     if (!$this->entityClassReflection) {
         $this->entityClassReflection = new \ReflectionClass($this->entityClassName);
     }
     return $this->entityClassReflection->newInstance();
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:10,代码来源:ModelFactory.php

示例3: display

 public function display($url)
 {
     $data = (object) json_decode(file_get_contents('php://input'), true);
     $reflection = new ReflectionClass($data->_type);
     if ($reflection->isSubclassOf('DataSource')) {
         $object = $reflection->newInstance();
         $object->parameters()->{'root-element'} = 'data';
         foreach ($data->_parameters as $key => $value) {
             $object->parameters()->{$key} = $value;
         }
         $result = $object->render(new Register());
         header('content-type: text/xml');
         echo $result->saveXML();
         exit;
     }
     if ($reflection->isSubclassOf('Event')) {
         $object = $reflection->newInstance();
         $object->parameters()->{'root-element'} = 'data';
         foreach ($data->_parameters as $key => $value) {
             $object->parameters()->{$key} = $value;
         }
         $result = $object->trigger(new Register(), (array) $data->_data);
         header('content-type: text/xml');
         echo $result->saveXML();
         exit;
     }
 }
开发者ID:psychoticmeowArchives,项目名称:javascript_api,代码行数:27,代码来源:api.php

示例4: getModuleInstanceByTypeAndName

 public static function getModuleInstanceByTypeAndName($sType, $sName)
 {
     if (!$sName) {
         throw new Exception("Exception in Module::getModuleInstanceByTypeAndName(): module name is empty");
     }
     $sClassName = self::getClassNameByTypeAndName($sType, $sName);
     if (!self::isModuleEnabled($sType, $sName)) {
         throw new Exception("Exception in Module::getModuleInstanceByTypeAndName(): tried to instanciate disabled module {$sType}.{$sName}");
     }
     $aArgs = array_slice(func_get_args(), 2);
     $oClass = new ReflectionClass($sClassName);
     if ($sClassName::isSingleton()) {
         if (!isset(self::$SINGLETONS[$sClassName])) {
             try {
                 self::$SINGLETONS[$sClassName] = $oClass->newInstanceArgs($aArgs);
             } catch (ReflectionException $ex) {
                 self::$SINGLETONS[$sClassName] = $oClass->newInstance();
             }
         }
         return self::$SINGLETONS[$sClassName];
     }
     try {
         return $oClass->newInstanceArgs($aArgs);
         //Does not work in PHP < 5.1.3
     } catch (ReflectionException $ex) {
         return $oClass->newInstance();
         //Does not work in PHP < 5.1.3
     }
 }
开发者ID:rapila,项目名称:cms-base,代码行数:29,代码来源:Module.php

示例5: test

function test($class)
{
    echo "====>{$class}\n";
    try {
        $ref = new ReflectionClass($class);
    } catch (ReflectionException $e) {
        var_dump($e->getMessage());
        return;
        // only here
    }
    echo "====>newInstance()\n";
    try {
        var_dump($ref->newInstance());
    } catch (ReflectionException $e) {
        var_dump($e->getMessage());
    }
    echo "====>newInstance(25)\n";
    try {
        var_dump($ref->newInstance(25));
    } catch (ReflectionException $e) {
        var_dump($e->getMessage());
    }
    echo "====>newInstance(25, 42)\n";
    try {
        var_dump($ref->newInstance(25, 42));
    } catch (ReflectionException $e) {
        var_dump($e->getMessage());
    }
    echo "\n";
}
开发者ID:gleamingthecube,项目名称:php,代码行数:30,代码来源:ext_reflection_tests_007.php

示例6: createValidator

 /**
  * Create validator
  *
  * @param $validator
  * @return \Phalcon\Validation\ValidatorInterface
  * @throws \Engine\Exception
  */
 public function createValidator($validator)
 {
     if ($validator instanceof ValidatorInterface) {
         return $validator;
     } elseif (is_array($validator)) {
         $origName = ucfirst($validator['validator']);
         if ($class = $this->getValidatorClassName($origName)) {
             if (empty($validator['options'])) {
                 $validator = new $class();
             } else {
                 $r = new \ReflectionClass($class);
                 if ($r->hasMethod('__construct')) {
                     $validator = $r->newInstance($validator['options']);
                 } else {
                     $validator = $r->newInstance();
                 }
             }
         }
     } elseif (is_string($validator)) {
         $origName = ucfirst($validator);
         if ($class = $this->getValidatorClassName($origName)) {
             $validator = new $class();
         }
     } else {
         throw new \Engine\Exception("Validator '{$validator}' not exists");
     }
     return $validator;
 }
开发者ID:tashik,项目名称:phalcon_core,代码行数:35,代码来源:Validators.php

示例7: invoke

 /**
  * @param array|null $args
  *
  * @return object
  */
 function invoke(array $args = null)
 {
     if ($args !== null) {
         return $this->reflectionClass->newInstanceArgs($args);
     }
     return $this->reflectionClass->newInstance();
 }
开发者ID:filecage,项目名称:creator,代码行数:12,代码来源:Creatable.php

示例8: testGetSingle

 public function testGetSingle()
 {
     $singletags = ['br', 'clear', 'col', 'hr', 'xkcd'];
     $method = $this->reflectionClass->getMethod('getSingle');
     $this->parser = $this->reflectionClass->newInstance();
     $this->assertEquals($singletags, $method->invoke($this->parser));
 }
开发者ID:chillerlan,项目名称:bbcode,代码行数:7,代码来源:ParserTest.php

示例9: instantiateController

 /**
  *
  * @param string $class
  * @return BaseController
  */
 protected function instantiateController($class)
 {
     $reflection = new \ReflectionClass($class);
     if ($reflection->isSubclassOf('Tracker\\Controller\\BaseController')) {
         return $reflection->newInstance($this->app);
     }
     return $reflection->newInstance();
 }
开发者ID:snikolow,项目名称:silex-issue-tracker,代码行数:13,代码来源:ControllerResolver.php

示例10: getInst

 /**
  * Метод формирует экземпляр класса на основе строки.
  * После будет применён фильтр, если он есть.
  * 
  * @return object
  */
 private function getInst(array $row)
 {
     if ($this->constructorParams) {
         $args = $this->constructorParams;
         $args[] = $row;
         return $this->RC->newInstanceArgs($args);
     } else {
         return $this->RC->newInstance($row);
     }
 }
开发者ID:ilivanoff,项目名称:www,代码行数:16,代码来源:ObjectQueryFetcher.php

示例11: getChildren

 /**
  * @see \RecursiveIterator:getChildren();
  */
 public function getChildren()
 {
     if ($this->current() instanceof self) {
         return $this->current();
     }
     if (empty($this->ref)) {
         $this->ref = new \ReflectionClass($this);
     }
     return $this->ref->newInstance($this->current() . '/');
 }
开发者ID:stealth35,项目名称:stdlib,代码行数:13,代码来源:RecursiveZipArchiveIterator.php

示例12: createInstance

 /**
  * Creates a new instance for the class
  */
 public static function createInstance($className, $args = [])
 {
     $reflection = new \ReflectionClass($className);
     if ($reflection->implementsInterface('App\\Interfaces\\SingletonInterface')) {
         if (isset(self::$singletones[$className])) {
             return self::$singletones[$className];
         } else {
             $instance = $args ? $reflection->newInstanceArgs($args) : $reflection->newInstance();
             self::$singletones[$className] = $instance;
         }
     } else {
         $instance = $args ? $reflection->newInstanceArgs($args) : $reflection->newInstance();
     }
     return $instance;
 }
开发者ID:atudz,项目名称:snapneat,代码行数:18,代码来源:FactoryCore.php

示例13: get

 /**
  * @param mixed   $id
  * @param boolean $forceInstance Whether returns an empty instance when no result
  *
  * @return StaticEntity|null
  */
 public function get($id, $forceInstance = false)
 {
     if (array_key_exists($id, $this->instances)) {
         return $this->instances[$id];
     } elseif (!($data = $this->getData($id))) {
         return $forceInstance ? $this->reflection->newInstance() : null;
     }
     $this->instances[$id] = $this->reflection->newInstance();
     foreach ($data as $property => $value) {
         $reflectionProperty = $this->reflection->getProperty($property);
         $reflectionProperty->setAccessible(true);
         $reflectionProperty->setValue($this->instances[$id], $value);
     }
     return $this->instances[$id];
 }
开发者ID:byscripts,项目名称:static-entity,代码行数:21,代码来源:StaticEntityManager.php

示例14: Deserialize

 public function Deserialize($Root)
 {
     $result = null;
     $counter = 0;
     foreach ($Root as $member) {
         $instance = new ReflectionClass($member->getName());
         $ins = $instance->newInstance();
         foreach ($member as $child) {
             $rp = $instance->getMethod("set_" . $child->getName());
             if (count($child->children()) == 0) {
                 $rp->invoke($ins, $child);
             } else {
                 $rp->invoke($ins, $this->Deserialize($child->children()));
                 echo $child;
             }
         }
         if (count($Root) == 1) {
             return $ins;
         } else {
             $result[$counter] = $ins;
             $counter++;
         }
         if ($counter == count($Root)) {
             return $result;
         }
     }
 }
开发者ID:vicenteguerra,项目名称:Flashbuy,代码行数:27,代码来源:Serializer.php

示例15: instantiate

 /**
  * Instantiates objects by class and id, respecting pattern implemented by given class
  * 
  * @param string $class Class name
  * @param $id
  * @return unknown_type
  */
 public static function instantiate($class, $id = null)
 {
     if (!strlen($class)) {
         require_once 'Oops/Exception.php';
         throw new Oops_Exception("Empty class name given");
     }
     if (!Oops_Loader::find($class)) {
         require_once 'Oops/Exception.php';
         throw new Oops_Exception("Class '{$class}' not found");
     }
     $reflectionClass = new ReflectionClass($class);
     if ($reflectionClass->implementsInterface('Oops_Pattern_Identifiable_Factored_Interface')) {
         /**
          * Object can be instantiated using corresponding factory
          */
         $factoryCallback = call_user_func($class, 'getFactoryCallback');
         $result = call_user_func($factoryCallback, $id);
     } elseif ($reflectionClass->implementsInterface('Oops_Pattern_Identifiable_Singleton_Interface')) {
         /**
          * This object can be instantiated using $class::getInstance($id)
          */
         $result = call_user_func(array($class, 'getInstance'), $id);
     } elseif ($reflectionClass->implementsInterface('Oops_Pattern_Singleton_Interface')) {
         /**
          * This object is the single available instance of this class, so it can be instantiated using $class::getInstance()
          */
         $result = call_user_func(array($class, 'getInstance'));
     } else {
         /**
          * This type of object should be constructed with given $id
          */
         $result = $reflectionClass->newInstance($id);
     }
     return $result;
 }
开发者ID:laiello,项目名称:oops-project,代码行数:42,代码来源:Factory.php


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