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


PHP ReflectionParameter::getClass方法代码示例

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


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

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

示例2: getParamTypeHint

 public function getParamTypeHint(\ReflectionFunctionAbstract $function, \ReflectionParameter $param, array $arguments = [])
 {
     $lowParam = strtolower($param->name);
     if ($function instanceof \ReflectionMethod) {
         $lowClass = strtolower($function->class);
         $lowMethod = strtolower($function->name);
         $paramCacheKey = self::CACHE_KEY_CLASSES . "{$lowClass}.{$lowMethod}.param-{$lowParam}";
     } else {
         $lowFunc = strtolower($function->name);
         $paramCacheKey = $lowFunc !== '{closure}' ? self::CACHE_KEY_FUNCS . ".{$lowFunc}.param-{$lowParam}" : null;
     }
     $typeHint = $paramCacheKey === null ? false : $this->cache->fetch($paramCacheKey);
     if (false !== $typeHint) {
         return $typeHint;
     }
     if ($reflectionClass = $param->getClass()) {
         $typeHint = $reflectionClass->getName();
         $classCacheKey = self::CACHE_KEY_CLASSES . strtolower($typeHint);
         $this->cache->store($classCacheKey, $this->getClass($param->getClass()->getName()));
     } elseif ($function instanceof \ReflectionMethod && ($docBlockParams = $this->getDocBlock($function)->getTagsByName('param')) && !empty($docBlockParams)) {
         $typeHint = $this->getParamDocBlockHint($docBlockParams, $param, $arguments);
         // store the ExtendedReflectionClass in the cache
         if ($typeHint !== false) {
             $classCacheKey = self::CACHE_KEY_CLASSES . strtolower($typeHint);
             $this->cache->store($classCacheKey, $this->getClass($typeHint));
         }
     } else {
         $typeHint = null;
     }
     $this->cache->store($paramCacheKey, $typeHint);
     return $typeHint;
 }
开发者ID:cmpayments,项目名称:atreyu,代码行数:32,代码来源:CachingReflector.php

示例3: from

 /**
  * @return self
  */
 public static function from(\ReflectionParameter $from)
 {
     $param = new static($from->getName());
     $param->reference = $from->isPassedByReference();
     if (PHP_VERSION_ID >= 70000) {
         $param->typeHint = $from->hasType() ? (string) $from->getType() : NULL;
     } elseif ($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;
     return $param;
 }
开发者ID:luminousinfoways,项目名称:pccfoas,代码行数:28,代码来源:Parameter.php

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

示例5: getDeclaration

 public function getDeclaration()
 {
     if ($this->reflector->isArray()) {
         $code = 'array ';
     } else {
         $class = $this->reflector->getClass();
         if ($class !== null) {
             $code = $class->name . ' ';
         } else {
             $code = '';
         }
     }
     $code .= '$' . $this->reflector->name;
     if ($this->reflector->isOptional()) {
         $default = $this->reflector->getDefaultValue();
         if (is_null($default)) {
             $default = 'null';
         } elseif (is_bool($default)) {
             $default = $default ? 'true' : 'false';
         } elseif (is_string($default)) {
             $default = "'" . $default . "'";
         } elseif (is_numeric($default)) {
             $default = strval($default);
         } elseif (is_array($default)) {
             $default = 'array()';
         } else {
             echo 'Warning: unknown default type for ' . $this->getMethod()->getFullName() . PHP_EOL;
             var_dump($default);
             $default = 'null';
         }
         $code .= ' = ' . $default;
     }
     return $code;
 }
开发者ID:zhangjingli35,项目名称:hamcrest,代码行数:34,代码来源:FactoryParameter.php

示例6: getArgumentMock

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

示例7: isGoutte1

 private function isGoutte1()
 {
     $refl = new \ReflectionParameter(array('Goutte\\Client', 'setClient'), 0);
     if ($refl->getClass() && 'Guzzle\\Http\\ClientInterface' === $refl->getClass()->getName()) {
         return true;
     }
     return false;
 }
开发者ID:obrianhc,项目名称:memestime,代码行数:8,代码来源:GoutteFactory.php

示例8: getClass

 /**
  * @inheritdoc
  */
 public function getClass()
 {
     $class = $this->parameter->getClass();
     if ($class) {
         return $class->getName();
     }
     return null;
 }
开发者ID:piotrminkina,项目名称:resource-resolver-bundle,代码行数:11,代码来源:CallbackParameter.php

示例9: getParameterInfo

 private function getParameterInfo(\ReflectionParameter $parameter)
 {
     $paramName = '$' . $parameter->getName() . '=null';
     if ($parameter->isPassedByReference()) {
         $paramName = '&' . $paramName;
     }
     $paramType = $parameter->getClass() !== null ? $parameter->getClass()->getName() : '';
     return "{$paramType} {$paramName}";
 }
开发者ID:marcellorvalle,项目名称:php-sandbox,代码行数:9,代码来源:SurrogateGenerator.php

示例10: getTypeHint

 /**
  * return type hint, if any (none or object type - inteface, class, ...)
  *
  * @return string
  */
 public function getTypeHint()
 {
     if ($this->typeHint === null) {
         if (($class = $this->reflectionParameter->getClass()) !== null) {
             $this->typeHint = $class->getName();
         }
     }
     return $this->typeHint;
 }
开发者ID:edde-framework,项目名称:edde,代码行数:14,代码来源:ParameterReflection.php

示例11: getType

 private function getType(\ReflectionParameter $param)
 {
     if ($param->getClass() && $param->getClass()->getName()) {
         return $param->getClass()->getName();
     }
     if ($param->isArray()) {
         return 'Array';
     }
 }
开发者ID:trajedy,项目名称:ThruwayBundle,代码行数:9,代码来源:ThruwayDebugCommand.php

示例12: validate

 public function validate(\ReflectionParameter $parameter, $argument)
 {
     if ($parameter->isArray()) {
         $this->validateArrayArgument($argument);
     } elseif ($parameter->getClass()) {
         $this->validateObjectArgument($parameter->getClass()->getName(), $argument, $parameter->allowsNull());
     }
     // other arguments don't need to be or can't be validated
 }
开发者ID:bendavies,项目名称:symfony-service-definition-validator,代码行数:9,代码来源:ArgumentValidator.php

示例13: getParameterDependency

 /**
  * @param Horde_Injector $injector
  * @param ReflectionParameter $method
  *
  * @return mixed
  * @throws Horde_Injector_Exception
  */
 public function getParameterDependency(Horde_Injector $injector, ReflectionParameter $parameter)
 {
     if ($parameter->getClass()) {
         return $injector->getInstance($parameter->getClass()->getName());
     } elseif ($parameter->isOptional()) {
         return $parameter->getDefaultValue();
     }
     throw new Horde_Injector_Exception("Untyped parameter \$" . $parameter->getName() . "can't be fulfilled");
 }
开发者ID:horde,项目名称:horde,代码行数:16,代码来源:DependencyFinder.php

示例14: getTypeByReflectionParameter

 /**
  * @param \ReflectionParameter $reflectionParameter
  *
  * @return null|string
  */
 protected function getTypeByReflectionParameter(\ReflectionParameter $reflectionParameter)
 {
     if ($reflectionParameter->getClass()) {
         return $reflectionParameter->getClass()->getName();
     }
     if ($reflectionParameter->isArray()) {
         return 'array';
     }
     return null;
 }
开发者ID:jobcloud,项目名称:jobcloud-closure-validator,代码行数:15,代码来源:Validator.php

示例15: getArgument

 private function getArgument(\ReflectionParameter $argument)
 {
     if ($argument->isOptional()) {
         return $argument->getDefaultValue();
     }
     if ($argument->allowsNull()) {
         return null;
     }
     if ($argument->getClass()) {
         return $this->getMockBuilder($argument->getClass()->getName())->disableOriginalConstructor()->getMock();
     }
     return null;
 }
开发者ID:dunglas,项目名称:Mink,代码行数:13,代码来源:CoreDriverTest.php


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