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


PHP ReflectionFunction::getDeclaringClass方法代码示例

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


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

示例1: from

 /**
  * @return self
  */
 public static function from($from) : self
 {
     if (is_string($from) && strpos($from, '::')) {
         $from = new \ReflectionMethod($from);
     } elseif (is_array($from)) {
         $from = new \ReflectionMethod($from[0], $from[1]);
     } elseif (!$from instanceof \ReflectionFunctionAbstract) {
         $from = new \ReflectionFunction($from);
     }
     $method = new static();
     $method->name = $from->isClosure() ? NULL : $from->getName();
     foreach ($from->getParameters() as $param) {
         $method->parameters[$param->getName()] = Parameter::from($param);
     }
     if ($from instanceof \ReflectionMethod) {
         $method->static = $from->isStatic();
         $method->visibility = $from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : NULL);
         $method->final = $from->isFinal();
         $method->abstract = $from->isAbstract() && !$from->getDeclaringClass()->isInterface();
         $method->body = $from->isAbstract() ? FALSE : '';
     }
     $method->returnReference = $from->returnsReference();
     $method->variadic = PHP_VERSION_ID >= 50600 && $from->isVariadic();
     $method->comment = $from->getDocComment() ? preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t")) : NULL;
     if (PHP_VERSION_ID >= 70000 && $from->hasReturnType()) {
         $returnType = $from->getReturnType();
         $method->returnType = $returnType->isBuiltin() ? (string) $returnType : '\\' . $returnType;
     }
     return $method;
 }
开发者ID:kukulich,项目名称:php-generator,代码行数:33,代码来源:Method.php

示例2: factory

 /**
  * Factory.
  *
  * @param  ReflectionFunction|ReflectionMethod $function
  * @param  array                               $codeCoverage
  * @return PHPUnit_Util_Metrics_Method
  */
 public static function factory($function, &$codeCoverage = array())
 {
     if ($function instanceof ReflectionMethod) {
         $scope = $function->getDeclaringClass()->getName();
     } else {
         $scope = 'global';
     }
     $name = $function->getName();
     if (!isset(self::$cache[$scope][$name])) {
         self::$cache[$scope][$name] = new PHPUnit_Util_Metrics_Function($scope, $function, $codeCoverage);
     } else {
         if (!empty($codeCoverage) && self::$cache[$scope][$name]->getCoverage() == 0) {
             self::$cache[$scope][$name]->setCoverage($codeCoverage);
         }
     }
     return self::$cache[$scope][$name];
 }
开发者ID:kytvi2p,项目名称:ZettaFramework,代码行数:24,代码来源:Function.php

示例3: getArguments

 protected function getArguments($callable, $arguments)
 {
     $callType = $this->getAttribute('type');
     $callName = $this->getAttribute('name');
     $parameters = array();
     $named = false;
     foreach ($arguments as $name => $node) {
         if (!is_int($name)) {
             $named = true;
             $name = $this->normalizeName($name);
         } elseif ($named) {
             throw new Twig_Error_Syntax(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName));
         }
         $parameters[$name] = $node;
     }
     $isVariadic = $this->hasAttribute('is_variadic') && $this->getAttribute('is_variadic');
     if (!$named && !$isVariadic) {
         return $parameters;
     }
     if (!$callable) {
         if ($named) {
             $message = sprintf('Named arguments are not supported for %s "%s".', $callType, $callName);
         } else {
             $message = sprintf('Arbitrary positional arguments are not supported for %s "%s".', $callType, $callName);
         }
         throw new LogicException($message);
     }
     // manage named arguments
     if (is_array($callable)) {
         $r = new ReflectionMethod($callable[0], $callable[1]);
     } elseif (is_object($callable) && !$callable instanceof Closure) {
         $r = new ReflectionObject($callable);
         $r = $r->getMethod('__invoke');
     } elseif (is_string($callable) && false !== strpos($callable, '::')) {
         $r = new ReflectionMethod($callable);
     } else {
         $r = new ReflectionFunction($callable);
     }
     $definition = $r->getParameters();
     if ($this->hasNode('node')) {
         array_shift($definition);
     }
     if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) {
         array_shift($definition);
     }
     if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) {
         array_shift($definition);
     }
     if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) {
         foreach ($this->getAttribute('arguments') as $argument) {
             array_shift($definition);
         }
     }
     if ($isVariadic) {
         $argument = end($definition);
         if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && array() === $argument->getDefaultValue()) {
             array_pop($definition);
         } else {
             $callableName = $r->name;
             if ($r->getDeclaringClass()) {
                 $callableName = $r->getDeclaringClass()->name . '::' . $callableName;
             }
             throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".', $callableName, $callType, $callName));
         }
     }
     $arguments = array();
     $names = array();
     $missingArguments = array();
     $optionalArguments = array();
     $pos = 0;
     foreach ($definition as $param) {
         $names[] = $name = $this->normalizeName($param->name);
         if (array_key_exists($name, $parameters)) {
             if (array_key_exists($pos, $parameters)) {
                 throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName));
             }
             if (!empty($missingArguments)) {
                 throw new Twig_Error_Syntax(sprintf('Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".', $name, $callType, $callName, implode(', ', $names), count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments)));
             }
             $arguments = array_merge($arguments, $optionalArguments);
             $arguments[] = $parameters[$name];
             unset($parameters[$name]);
             $optionalArguments = array();
         } elseif (array_key_exists($pos, $parameters)) {
             $arguments = array_merge($arguments, $optionalArguments);
             $arguments[] = $parameters[$pos];
             unset($parameters[$pos]);
             $optionalArguments = array();
             ++$pos;
         } elseif ($param->isDefaultValueAvailable()) {
             $optionalArguments[] = new Twig_Node_Expression_Constant($param->getDefaultValue(), -1);
         } elseif ($param->isOptional()) {
             if (empty($parameters)) {
                 break;
             } else {
                 $missingArguments[] = $name;
             }
         } else {
             throw new Twig_Error_Syntax(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName));
         }
//.........这里部分代码省略.........
开发者ID:idwsdta,项目名称:INIT-frame,代码行数:101,代码来源:Call.php

示例4: getCallableParameters

 private function getCallableParameters($callable, $isVariadic)
 {
     if (is_array($callable)) {
         $r = new ReflectionMethod($callable[0], $callable[1]);
     } elseif (is_object($callable) && !$callable instanceof Closure) {
         $r = new ReflectionObject($callable);
         $r = $r->getMethod('__invoke');
     } elseif (is_string($callable) && false !== strpos($callable, '::')) {
         $r = new ReflectionMethod($callable);
     } else {
         $r = new ReflectionFunction($callable);
     }
     $parameters = $r->getParameters();
     if ($this->hasNode('node')) {
         array_shift($parameters);
     }
     if ($this->hasAttribute('needs_environment') && $this->getAttribute('needs_environment')) {
         array_shift($parameters);
     }
     if ($this->hasAttribute('needs_context') && $this->getAttribute('needs_context')) {
         array_shift($parameters);
     }
     if ($this->hasAttribute('arguments') && null !== $this->getAttribute('arguments')) {
         foreach ($this->getAttribute('arguments') as $argument) {
             array_shift($parameters);
         }
     }
     if ($isVariadic) {
         $argument = end($parameters);
         if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && array() === $argument->getDefaultValue()) {
             array_pop($parameters);
         } else {
             $callableName = $r->name;
             if ($r instanceof ReflectionMethod) {
                 $callableName = $r->getDeclaringClass()->name . '::' . $callableName;
             }
             throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".', $callableName, $this->getAttribute('type'), $this->getAttribute('name')));
         }
     }
     return $parameters;
 }
开发者ID:sharenjoy,项目名称:axes,代码行数:41,代码来源:Call.php


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