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


PHP Reflection::getReflectionClass方法代码示例

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


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

示例1: launch

 /**
  * @param null $instance
  * @param array $parameters
  * @param Manager $manager
  * @return mixed
  * @throws Exception
  */
 function launch($instance = null, $parameters, Manager $manager)
 {
     $arguments = array();
     foreach ($this->arguments as $index => $argument) {
         if (is_string($argument) && isset($parameters[$argument])) {
             $arguments[] = $parameters[$argument];
         } elseif ($argument instanceof Reference) {
             // find parameter by class
             $foundInParams = false;
             foreach ($parameters as $param) {
                 if (is_a($param, $argument->getClass())) {
                     $arguments[] = $param;
                     $foundInParams = true;
                     break;
                 }
             }
             if (!$foundInParams) {
                 $arguments[] = $argument->getInstance($manager);
             }
         } else {
             if (count(array_filter(array_keys($parameters), 'is_int')) > 0) {
                 $arguments[] = array_shift($parameters);
             } else {
                 if ($index < $this->requiredCount) {
                     throw new Exception(sprintf("Key %s for method %s::%s not found!", $argument, $this->class, $this->method));
                 }
             }
         }
     }
     if ($this->method == '__construct') {
         if (!count($arguments)) {
             return new $this->class();
         }
         return Reflection::getReflectionClass($this->class)->newInstanceArgs($arguments);
     }
     if (in_array($this->method, $manager->getInspector()->getPublicMethods($this->class))) {
         return call_user_func_array(array($instance, $this->method), $arguments);
     }
     return Reflection::getReflectionMethod($this->class, $this->method)->invokeArgs($instance, $arguments);
 }
开发者ID:cti,项目名称:di,代码行数:47,代码来源:Callback.php

示例2: getClassInjection

 /**
  * @param $class
  * @return array
  */
 public function getClassInjection($class)
 {
     if ($this->getCache()->contains(__METHOD__, func_get_args())) {
         return $this->getCache()->get(__METHOD__, func_get_args());
     }
     $injection = array();
     $reflectionClass = Reflection::getReflectionClass($class);
     foreach ($reflectionClass->getProperties() as $property) {
         if (stristr($property->getDocComment(), '@inject') || stristr($property->getDocComment(), '@new')) {
             foreach (explode("\n", $property->getDocComment()) as $line) {
                 if (!stristr($line, '@var')) {
                     continue;
                 }
                 foreach (explode(' ', substr($line, stripos($line, '@var') + 4)) as $item) {
                     if (strlen($item) > 0) {
                         $global = false;
                         if ($item[0] == '\\') {
                             $global = true;
                             $item = substr($item, 1);
                         }
                         $injected_class = trim(str_replace("\r", '', $item));
                         if (!$global) {
                             $aliases = array();
                             foreach (file($property->getDeclaringClass()->getFileName()) as $line) {
                                 if (strpos($line, 'use ') === 0) {
                                     $line = substr($line, 0, strpos($line, ';'));
                                     $chain = array_filter(explode(' ', $line), 'strlen');
                                     if (strpos($line, ' as ')) {
                                         $destination = $chain[1];
                                         $alias = $chain[3];
                                     } else {
                                         $destination = $chain[1];
                                         list($alias) = array_reverse(explode("\\", $chain[1]));
                                     }
                                     $aliases[$alias] = $destination;
                                 }
                                 if (strpos($line, 'class ') === 0) {
                                     break;
                                 }
                             }
                             if (isset($aliases[$injected_class])) {
                                 // imported with use statement
                                 $injected_class = $aliases[$injected_class];
                             } elseif (!strstr($injected_class, '\\')) {
                                 $injected_class = $reflectionClass->getNamespaceName() . '\\' . $injected_class;
                             } else {
                                 list($ns) = explode('\\', $injected_class);
                                 if (isset($aliases[$ns])) {
                                     $injected_class = $aliases[$ns] . substr($injected_class, strlen($ns));
                                 }
                             }
                         }
                         $injection[$property->getName()] = array('class' => $injected_class, 'new' => stristr($property->getDocComment(), '@new'));
                         break;
                     }
                 }
             }
         }
     }
     $this->getCache()->set(__METHOD__, func_get_args(), $injection);
     return $injection;
 }
开发者ID:cti,项目名称:di,代码行数:66,代码来源:Inspector.php

示例3: __construct

 public function __construct($model)
 {
     $this->_model = $model;
     $reflectionClass = Reflection::getReflectionClass($model);
     $properties = $reflectionClass->getStaticProperties();
     foreach (self::$_VALIDATION_TYPES as $type) {
         if (!empty($properties[$type])) {
             foreach ($properties[$type] as $validate) {
                 $validate['type'] = $type;
                 if (empty($validate['on']) || $validate['on'] === 'save') {
                     array_push($this->_registeredValidates['create'], $validate);
                     array_push($this->_registeredValidates['update'], $validate);
                     continue;
                 }
                 if ($validate['on'] === 'create') {
                     array_push($this->_registeredValidates['create'], $validate);
                     continue;
                 }
                 if ($validate['on'] === 'update') {
                     array_push($this->_registeredValidates['update'], $validate);
                     continue;
                 }
             }
         }
     }
 }
开发者ID:nanjingboy,项目名称:clown,代码行数:26,代码来源:Validation.php


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