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


PHP ReflectionClass::newInstanceArgs方法代码示例

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


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

示例1: evaluate

 public function evaluate($configFiles)
 {
     $routeDefinitions = $this->parse($configFiles);
     $routes = array();
     $limit = count($this->routes) > 0;
     foreach ($routeDefinitions as $name => $route) {
         // we only load routes defined in the app.yml from
         if ($limit && !in_array($this->getOriginalName($name), $this->routes)) {
             continue;
         }
         $r = new ReflectionClass($route[0]);
         if ($r->isSubclassOf('sfRouteCollection')) {
             $route[1][0]['requirements']['sw_app'] = $this->app;
             $route[1][0]['requirements']['sw_host'] = $this->host;
             $collection_route = $r->newInstanceArgs($route[1]);
             foreach ($collection_route->getRoutes() as $name => $route) {
                 $routes[$this->app . '.' . $name] = new swEncapsulateRoute($route, $this->host, $this->app);
             }
         } else {
             $route[1][2]['sw_app'] = $this->app;
             $route[1][2]['sw_host'] = $this->host;
             $routes[$name] = new swEncapsulateRoute($r->newInstanceArgs($route[1]), $this->host, $this->app);
         }
     }
     return $routes;
 }
开发者ID:robinkanters,项目名称:dnsleergemeenschap,代码行数:26,代码来源:swCrossApplicationRoutingConfigHandler.class.php

示例2: 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

示例3: toCall

 /**
  * 调用具体的业务逻辑接口,通常来说是项目中的
  *      controller,也可以RPC调用
  * @param Request $request
  * @return mixed
  * @throws \Simple\Application\Game\Cycle\Exception\GameCycleException
  */
 public function toCall(Request $request)
 {
     $head = $request->getHeader();
     $module = ucfirst($head[0]);
     $action = $head[1];
     // TODO 获取类的命名空间
     $cls = new \ReflectionClass(APP_TOP_NAMESPACE . '\\Controller\\' . $module . 'Controller');
     $instance = null;
     //优先调用init方法
     if ($cls->hasMethod('__init__')) {
         $initMethod = $cls->getMethod('__init__');
         if ($initMethod->isPublic() == true) {
             $instance = $cls->newInstanceArgs(array());
             $initMethod->invokeArgs($instance, array());
         }
     }
     $method = $cls->getMethod($action);
     if ($method->isPublic() == false) {
         throw new GameCycleException('无法调用接口:' . $module . '.' . $action);
     }
     if ($instance == null) {
         $instance = $cls->newInstanceArgs(array());
     }
     $ret = $method->invokeArgs($instance, array($request));
     if ($ret instanceof Response === false) {
         throw new GameCycleException('接口返回的对象必须为:Response对象。');
     }
     return $ret;
 }
开发者ID:songsihan,项目名称:simple,代码行数:36,代码来源:Caller.php

示例4: 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

示例5: create

 public function create($component, array $args = [], $forceNewInstance = false, $share = [])
 {
     if (!$forceNewInstance && isset($this->instances[$component])) {
         return $this->instances[$component];
     }
     if (empty($this->cache[$component])) {
         $rule = $this->getRule($component);
         $class = new \ReflectionClass($rule->instanceOf ? $rule->instanceOf : $component);
         $constructor = $class->getConstructor();
         $params = $constructor ? $this->getParams($constructor, $rule) : null;
         $this->cache[$component] = function ($args) use($component, $rule, $class, $constructor, $params, $share) {
             if ($rule->shared) {
                 if ($constructor) {
                     try {
                         $this->instances[$component] = $object = $class->newInstanceWithoutConstructor();
                         $constructor->invokeArgs($object, $params($args, $share));
                     } catch (\ReflectionException $r) {
                         $this->instances[$component] = $object = $class->newInstanceArgs($params($args, $share));
                     }
                 } else {
                     $this->instances[$component] = $object = $class->newInstanceWithoutConstructor();
                 }
             } else {
                 $object = $params ? $class->newInstanceArgs($params($args, $share)) : new $class->name();
             }
             if ($rule->call) {
                 foreach ($rule->call as $call) {
                     $class->getMethod($call[0])->invokeArgs($object, call_user_func($this->getParams($class->getMethod($call[0]), $rule), $this->expand($call[1])));
                 }
             }
             return $object;
         };
     }
     return $this->cache[$component]($args);
 }
开发者ID:kvox,项目名称:TVSS,代码行数:35,代码来源:dice.php

示例6: create

 public static function create($arg1, $arg2 = null)
 {
     if ($arg1 instanceof AbstractValidator) {
         return $arg1;
     }
     if (is_array($arg1) && !isset($arg1['class'])) {
         return self::createGroup($arg1);
     }
     if (is_string($arg1)) {
         $class = $arg1;
         $options = $arg2;
     } else {
         $class = $arg1['class'];
         if (isset($arg1['options'])) {
             $options = $arg1['options'];
         }
     }
     $reflection = new \ReflectionClass($class);
     if (isset($options)) {
         $validator = $reflection->newInstanceArgs($options);
     } else {
         $validator = $reflection->newInstanceArgs();
     }
     return $validator;
 }
开发者ID:superdweebie,项目名称:validator,代码行数:25,代码来源:Factory.php

示例7: createMultiple

 /**
  * Populates a set of models with the data from end user.
  * This method is mainly used to collect tabular data input.
  * The data to be loaded for each model is `$data[formName][index]`, where `formName`
  * refers to the sort name of model class, and `index` the index of the model in the `$data` array.
  * If `$formName` is empty, `$data[index]` will be used to populate each model.
  * The data being populated to each model is subject to the safety check by [[setAttributes()]].
  * @param string $class Model class name.
  * @param array $data the data array. This is usually `$_POST` or `$_GET`, but can also be any valid array
  * supplied by end user.
  * @param string $formName the form name to be used for loading the data into the models.
  * If not set, it will use the sort name of called class.
  * @param Model[] $origin original models to be populated. It will be check using `$keys` with supplied data.
  * If same then will be used for result model.
  * @param array $options Option to model
  * - scenario for model.
  * - arguments The parameters to be passed to the class constructor as an array.
  * @return boolean|Model[] whether at least one of the models is successfully populated.
  */
 public static function createMultiple($class, $data, $formName = null, &$origin = [], $options = [])
 {
     $reflector = new \ReflectionClass($class);
     $args = isset($options['arguments']) ? $options['arguments'] : [];
     if ($formName === null) {
         /* @var $model Model */
         $model = empty($args) ? new $class() : $reflector->newInstanceArgs($args);
         $formName = $model->formName();
     }
     if ($formName != '') {
         $data = isset($data[$formName]) ? $data[$formName] : null;
     }
     if ($data === null) {
         return false;
     }
     $models = [];
     foreach ($data as $i => $row) {
         $model = null;
         if (isset($origin[$i])) {
             $model = $origin[$i];
             unset($origin[$i]);
         } else {
             $model = empty($args) ? new $class() : $reflector->newInstanceArgs($args);
         }
         if (isset($options['scenario'])) {
             $model->scenario = $options['scenario'];
         }
         $model->load($row, '');
         $models[$i] = $model;
     }
     return $models;
 }
开发者ID:mdmsoft,项目名称:yii2-widgets,代码行数:51,代码来源:ModelHelper.php

示例8: testSimilarTo

 /**
  * Test the Notice->similar_to(<Notice>) method
  *
  * @test
  * @dataProvider providerSimilarTo
  */
 public function testSimilarTo($args_one, $args_two, $expected)
 {
     $reflected = new ReflectionClass('Notice');
     $notice_one = $reflected->newInstanceArgs($args_one);
     $notice_two = $reflected->newInstanceArgs($args_two);
     $this->assertSame($expected, $notice_one->similar_to($notice_two));
 }
开发者ID:synapsestudios,项目名称:kohana-notices,代码行数:13,代码来源:NoticeTest.php

示例9: testGetAllowed

 public function testGetAllowed()
 {
     $options = new ParserOptions();
     $options->allowed_tags = ['noparse', 'code', 'img'];
     $method = $this->reflectionClass->getMethod('getAllowed');
     $this->parser = $this->reflectionClass->newInstanceArgs([$options]);
     $this->assertEquals(['code', 'img', 'noparse'], $method->invoke($this->parser));
 }
开发者ID:chillerlan,项目名称:bbcode,代码行数:8,代码来源:ParserTest.php

示例10: constructClass

 /**
  * Construct new class by class name
  * @param string $className class that want to be constructed.
  * @param array $args Constructor params if exist
  * @return object Constructed Class
  */
 public static function constructClass($className, array $args = array())
 {
     $reflector = new \ReflectionClass($className);
     if ($reflector->hasMethod('__construct') && count($args) > 0) {
         return $reflector->newInstanceArgs($args);
     }
     return $reflector->newInstanceArgs();
 }
开发者ID:cynode,项目名称:asset-manager,代码行数:14,代码来源:Reflect.php

示例11: createInstance

 /**
  * @param array $args
  *
  * @return \IntlDateFormatter
  */
 protected static function createInstance(array $args = array())
 {
     if (!self::$reflection) {
         self::$reflection = new \ReflectionClass('IntlDateFormatter');
     }
     $instance = self::$reflection->newInstanceArgs($args);
     self::checkInternalClass($instance, '\\IntlDateFormatter', $args);
     return $instance;
 }
开发者ID:dearaujoj,项目名称:SonataIntlBundle,代码行数:14,代码来源:DateTimeHelper.php

示例12: 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

示例13: create

 /**
  * {@inheritdoc}
  */
 public function create(array $arguments = [])
 {
     if (empty($arguments[0])) {
         $arguments[0] = $this->createEntity();
     }
     if (!$this->modelClassReflection) {
         $this->modelClassReflection = new \ReflectionClass($this->modelClassName);
     }
     return $this->modelClassReflection->newInstanceArgs($arguments);
 }
开发者ID:hafeez3000,项目名称:orocommerce,代码行数:13,代码来源:ModelFactory.php

示例14: instantiate

 /**
  * @param $class
  * @param $args
  * @return object
  */
 private static function instantiate($class, $args)
 {
     //BOOOOO, this produces a parse error on less than 5.6.0
     //        if (version_compare(phpversion(), '5.6.0') !== -1) {
     //            $instance = new $class(...$args);
     //        } else {
     $reflect = new \ReflectionClass($class);
     $instance = $args === null || $args === false ? $reflect->newInstanceArgs() : $reflect->newInstanceArgs($args);
     //        }
     return $instance;
 }
开发者ID:twhiston,项目名称:twlib,代码行数:16,代码来源:Instantiate.php

示例15: create

 public function create($class, array $args = array())
 {
     $this->validate($class, $args);
     $reflection = new \ReflectionClass($class);
     if ($reflection->getConstructor()) {
         $object = $reflection->newInstanceArgs($args);
     } else {
         $object = $reflection->newInstanceArgs();
     }
     return $object;
 }
开发者ID:moriony,项目名称:instantiator,代码行数:11,代码来源:Base.php


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