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


PHP ReflectionParameter::getDeclaringClass方法代码示例

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


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

示例1: from

 /**
  * @return self
  */
 public static function from(\ReflectionParameter $from)
 {
     $param = new static();
     $param->name = $from->getName();
     $param->reference = $from->isPassedByReference();
     if ($from->isArray()) {
         $param->typeHint = 'array';
     } elseif (PHP_VERSION_ID >= 50400 && $from->isCallable()) {
         $param->typeHint = 'callable';
     } else {
         try {
             $param->typeHint = $from->getClass() ? '\\' . $from->getClass()->getName() : NULL;
         } catch (\ReflectionException $e) {
             if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
                 $param->typeHint = '\\' . $m[1];
             } else {
                 throw $e;
             }
         }
     }
     $param->optional = PHP_VERSION_ID < 50407 ? $from->isOptional() || $param->typeHint && $from->allowsNull() : $from->isDefaultValueAvailable();
     $param->defaultValue = PHP_VERSION_ID === 50316 ? $from->isOptional() : $from->isDefaultValueAvailable() ? $from->getDefaultValue() : NULL;
     $namespace = $from->getDeclaringClass() ? $from->getDeclaringClass()->getNamespaceName() : NULL;
     $namespace = $namespace ? "\\{$namespace}\\" : '\\';
     if (Nette\Utils\Strings::startsWith($param->typeHint, $namespace)) {
         $param->typeHint = substr($param->typeHint, strlen($namespace));
     }
     return $param;
 }
开发者ID:NetteCamp,项目名称:2015-nextras-orm-twitter,代码行数:32,代码来源:Parameter.php

示例2: getType

 public function getType() : Type
 {
     if ($this->type === null) {
         $phpDocType = $this->phpDocType;
         if ($phpDocType !== null && $this->reflection->isDefaultValueAvailable() && $this->reflection->getDefaultValue() === null) {
             $phpDocType = $phpDocType->makeNullable();
         }
         $this->type = TypehintHelper::decideTypeFromReflection($this->reflection->getType(), $phpDocType, $this->reflection->getDeclaringClass() !== null ? $this->reflection->getDeclaringClass()->getName() : null, $this->reflection->isVariadic());
     }
     return $this->type;
 }
开发者ID:phpstan,项目名称:phpstan,代码行数:11,代码来源:PhpParameterReflection.php

示例3: getParameterAnnotations

 public function getParameterAnnotations(\ReflectionParameter $parameter)
 {
     $class = $parameter->getDeclaringClass() ?: 'Closure';
     $method = $parameter->getDeclaringFunction();
     if (!$method->isUserDefined()) {
         return array();
     }
     $context = 'parameter ' . ($class === 'Closure' ? $class : $class->getName()) . '::' . $method->getName() . '($' . $parameter->getName() . ')';
     if ($class === 'Closure') {
         $this->parser->setImports($this->getClosureImports($method));
     } else {
         $this->parser->setImports($this->getImports($class));
         $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
     }
     $lines = file($method->getFileName());
     $lines = array_slice($lines, $start = $method->getStartLine() - 1, $method->getEndLine() - $start);
     $methodBody = Implode($lines);
     $methodBody = str_replace("\n", null, $methodBody);
     $signature = preg_split('/\\)\\s*\\{/', $methodBody);
     $signature = $signature[0];
     $signature = substr($signature, strpos($signature, "function"));
     if (preg_match_all('/\\/\\*\\*(.*?)\\*\\/' . '.*?\\$(\\w+)/', $signature, $matches)) {
         $docComments = $matches[1];
         $names = $matches[2];
         for ($i = 0, $len = count($names); $i < $len; ++$i) {
             if ($names[$i] === $parameter->name) {
                 return $this->parser->parse($docComments[$i], $context);
             }
         }
     }
     return array();
 }
开发者ID:spotframework,项目名称:spot,代码行数:32,代码来源:ReaderImpl.php

示例4: getDeclaringClass

 public function getDeclaringClass()
 {
     $phpReflection = parent::getDeclaringClass();
     $zendReflection = new ZendL_Reflection_Class($phpReflection->getName());
     unset($phpReflection);
     return $zendReflection;
 }
开发者ID:lortnus,项目名称:zf1,代码行数:7,代码来源:Parameter.php

示例5: getArgumentMock

 /**
  * @param \ReflectionParameter $parameter
  * @return mixed
  */
 private function getArgumentMock(\ReflectionParameter $parameter)
 {
     if ($parameter->getClass() !== null) {
         return $this->testCase->getMockBuilder($parameter->getClass()->getName())->disableOriginalConstructor()->getMock();
     }
     throw new \Mocktainer\UnmockableMethodArgumentException($parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $parameter->getName());
 }
开发者ID:paranoiq,项目名称:mocktainer,代码行数:11,代码来源:Mocktainer.php

示例6: getDeclaringClass

 /**
  * Gets the declaring class.
  * 
  * @return \Wingu\OctopusCore\Reflection\ReflectionClass
  */
 public function getDeclaringClass()
 {
     $class = parent::getDeclaringClass();
     if ($class !== null) {
         $class = new ReflectionClass($class->getName());
     }
     return $class;
 }
开发者ID:williamamed,项目名称:Raptor2,代码行数:13,代码来源:ReflectionParameter.php

示例7: getDependency

 protected function getDependency(\ReflectionParameter $param, $container)
 {
     $dependency = $param->getClass();
     if (is_null($dependency)) {
         $message = "Unable to resolve [{$param->name}] in {$param->getDeclaringClass()->getName()}";
         $this->raiseException($message);
     }
     return $container->get($dependency->name);
 }
开发者ID:lucatume,项目名称:php-dependency-injection-benchmarks,代码行数:9,代码来源:ReflectionBuilder.php

示例8: getParameterAnnotations

 function getParameterAnnotations(\ReflectionParameter $parameter)
 {
     $key = "@[Annot]" . $parameter->getDeclaringClass() . "#" . $parameter->getDeclaringFunction() . "#" . $parameter->name;
     if (($annotations = $this->cache->fetch($key)) === false) {
         $annotations = $this->reader->getParameterAnnotations($parameter);
         $this->cache->save($key, $annotations);
     }
     return $annotations;
 }
开发者ID:spotframework,项目名称:spot,代码行数:9,代码来源:CachedReader.php

示例9: getDeclaringClass

 /**
  * Get declaring class reflection object
  *
  * @param  string $reflectionClass Reflection class to use
  * @return \Zend\Reflection\ReflectionClass
  */
 public function getDeclaringClass($reflectionClass = 'Zend\\Reflection\\ReflectionClass')
 {
     $phpReflection = parent::getDeclaringClass();
     $zendReflection = new $reflectionClass($phpReflection->getName());
     if (!$zendReflection instanceof ReflectionClass) {
         throw new Exception\InvalidArgumentException('Invalid reflection class provided; must extend Zend_Reflection_Class');
     }
     unset($phpReflection);
     return $zendReflection;
 }
开发者ID:navtis,项目名称:xerxes-pazpar2,代码行数:16,代码来源:ReflectionParameter.php

示例10: getDeclaringClass

 /**
  * Get declaring class reflection object
  *
  * @param  string $reflectionClass Reflection class to use
  * @return Zend_Reflection_Class
  */
 public function getDeclaringClass($reflectionClass = 'Zend_Reflection_Class')
 {
     $phpReflection = parent::getDeclaringClass();
     $zendReflection = new $reflectionClass($phpReflection->getName());
     if (!$zendReflection instanceof Zend_Reflection_Class) {
         #require_once 'Zend/Reflection/Exception.php';
         throw new Zend_Reflection_Exception('Invalid reflection class provided; must extend Zend_Reflection_Class');
     }
     unset($phpReflection);
     return $zendReflection;
 }
开发者ID:par-orillonsoft,项目名称:Magento,代码行数:17,代码来源:Parameter.php

示例11: getDeclaringClass

 /**
  * Returns in which class this parameter is defined (not the type hint of the parameter)
  * @return ezcReflectionClass
  */
 function getDeclaringClass()
 {
     if ($this->parameter != null) {
         $class = $this->parameter->getDeclaringClass();
     } else {
         $class = parent::getDeclaringClass();
     }
     if (!empty($class)) {
         return new ezcReflectionClass($class->getName());
     } else {
         return null;
     }
 }
开发者ID:zetacomponents,项目名称:reflection,代码行数:17,代码来源:parameter.php

示例12: resolveArgument

 private function resolveArgument(\ReflectionParameter $parameter)
 {
     $name = StringUtil::underscore($parameter->name);
     if ('container' === $name) {
         return $this->container;
     }
     if (isset($this->container[$name])) {
         return $this->container[$name];
     }
     if ($parameter->isOptional()) {
         return $parameter->getDefaultValue();
     }
     throw new \RuntimeException(sprintf('Unable to resolve parameter "%s" of class "%s" no service/parameter found with name "%s". ' . 'Consider adding a default value.', $name, $parameter->getDeclaringClass()->name, $name));
 }
开发者ID:rollerworks,项目名称:SkeletonDancer,代码行数:14,代码来源:ClassInitializer.php

示例13: buildField

 private static function buildField(\ReflectionParameter $parameter, $data)
 {
     // If parameter turns out to be an Object then recurse
     if (!empty($parameter->getClass())) {
         return self::build($parameter->getClass()->getName(), $data);
     }
     // If parameter is type of array, then check whether it is an array of Object
     if ($parameter->isArray()) {
         $possibleObjectClassName = $parameter->getDeclaringClass()->getName() . '_' . $parameter->getName() . '_item';
         if (class_exists($possibleObjectClassName)) {
             return array_map(function ($values) use($possibleObjectClassName) {
                 return self::build($possibleObjectClassName, $values);
             }, $data);
         }
     }
     return $data;
 }
开发者ID:learnosity,项目名称:learnosity-qti,代码行数:17,代码来源:EntityBuilder.php

示例14: denormalizeParameter

 /**
  * Denormalize a method parameter value.
  *
  * @param \ReflectionParameter $reflectionParameter
  * @param mixed $value Parameter value to denormalize
  * @return mixed
  */
 protected function denormalizeParameter(\ReflectionParameter $reflectionParameter, $value)
 {
     if ($reflectionParameter->getClass() === null && !$reflectionParameter->isArray()) {
         return $value;
     }
     if (!$this->serializer instanceof DenormalizerInterface) {
         throw new LogicException('Cannot denormalize because injected serializer is not a denormalizer');
     }
     if ($reflectionParameter->getClass() !== null) {
         return $this->serializer->denormalize($value, $reflectionParameter->getClass()->name);
     }
     if ($reflectionParameter->isArray()) {
         $className = $reflectionParameter->getDeclaringClass()->getName();
         $methodName = $reflectionParameter->getDeclaringFunction()->getName();
         $parameterName = $reflectionParameter->getName();
         return $this->serializer->denormalize($value, $className . '::' . $methodName . '(' . $parameterName . ')');
     }
     return $value;
 }
开发者ID:a-mayer,项目名称:boekkooi-broadway,代码行数:26,代码来源:AdvancedInstantiationTrait.php

示例15: getParameterType

 /**
  * @return string|NULL
  */
 public static function getParameterType(\ReflectionParameter $param)
 {
     if (PHP_VERSION_ID >= 70000) {
         if ($param->hasType()) {
             $type = PHP_VERSION_ID >= 70100 ? $param->getType()->getName() : (string) $param->getType();
             return strtolower($type) === 'self' ? $param->getDeclaringClass()->getName() : $type;
         }
     } elseif ($param->isArray() || $param->isCallable()) {
         return $param->isArray() ? 'array' : 'callable';
     } else {
         try {
             return ($ref = $param->getClass()) ? $ref->getName() : NULL;
         } catch (\ReflectionException $e) {
             if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
                 return $m[1];
             }
             throw $e;
         }
     }
 }
开发者ID:nette,项目名称:di,代码行数:23,代码来源:PhpReflection.php


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