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


PHP ReflectionParameter::getType方法代码示例

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


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

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

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

示例3: from

 /**
  * @return self
  */
 public static function from(\ReflectionParameter $from)
 {
     $param = new static();
     $param->name = $from->getName();
     $param->reference = $from->isPassedByReference();
     if (PHP_VERSION_ID >= 70000) {
         $type = $from->getType();
         $param->typeHint = $type ? ($type->isBuiltin() ? '' : '\\') . $type : NULL;
     } elseif ($from->isArray() || $from->isCallable()) {
         $param->typeHint = $from->isArray() ? 'array' : '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 = $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:JanTvrdik,项目名称:nette-php-generator,代码行数:33,代码来源:Parameter.php

示例4: canInject

 /**
  * @param ReflectionParameter $parameter
  * @param CollectionInterface $properties
  *
  * @return bool
  */
 private function canInject(\ReflectionParameter $parameter, CollectionInterface $properties) : bool
 {
     if (!$parameter->allowsNull() && !$properties->hasKey($parameter->name)) {
         return false;
     } else {
         if ($parameter->allowsNull() && !$properties->hasKey($parameter->name)) {
             return false;
         }
     }
     $property = $properties[$parameter->name];
     if ($parameter->hasType()) {
         $type = $parameter->getType();
         if ($type->isBuiltin()) {
             return (string) $type === gettype($property);
         } else {
             if (!is_object($property)) {
                 return false;
             }
         }
         $refl = new \ReflectionObject($property);
         $wishedClass = (string) $type;
         return get_class($property) === $wishedClass || $refl->isSubClassOf($wishedClass);
     }
     return true;
 }
开发者ID:Innmind,项目名称:Reflection,代码行数:31,代码来源:ReflectionInstanciator.php

示例5: __construct

 public function __construct(ReflectionParameter $param)
 {
     if (method_exists('ReflectionParameter', 'getType')) {
         if ($type = $param->getType()) {
             $this->type_hint = (string) $type;
         }
     } else {
         if ($param->isArray()) {
             $this->type_hint = 'array';
         } else {
             try {
                 if ($this->type_hint = $param->getClass()) {
                     $this->type_hint = $this->type_hint->name;
                 }
             } catch (ReflectionException $e) {
                 preg_match('/\\[\\s\\<\\w+?>\\s([\\w]+)/s', $param->__toString(), $matches);
                 $this->type_hint = isset($matches[1]) ? $matches[1] : '';
             }
         }
     }
     $this->reference = $param->isPassedByReference();
     $this->position = $param->getPosition();
     $this->name = $param->getName();
     if ($param->isDefaultValueAvailable()) {
         $this->default = var_export($param->getDefaultValue(), true);
     }
 }
开发者ID:jnvsor,项目名称:kint,代码行数:27,代码来源:Parameter.php

示例6: testGetType

 public function testGetType()
 {
     $p1 = new ReflectionParameter(new \ReflectionParameter([$this, 'method'], 'param'));
     $p2 = new ReflectionParameter(new \ReflectionParameter([$this, 'method'], 'param_2'));
     $p3 = new ReflectionParameter(new \ReflectionParameter([$this, 'method'], 'param_3'));
     $this->assertEquals('array', $p1->getType()->getName());
     $this->assertNull($p2->getType());
     $this->assertEquals('\\' . \Exception::class, $p3->getType()->getName());
 }
开发者ID:hostnet,项目名称:entity-plugin-lib,代码行数:9,代码来源:ReflectionParameterTest.php

示例7: setReflectionMetadata

 /**
  * Set initial reflection metadata into the parameter definition
  *
  * @param ParameterDefinition $parameterDefinition
  * @param \ReflectionParameter $reflectionParameter
  */
 public function setReflectionMetadata(ParameterDefinition $parameterDefinition, \ReflectionParameter $reflectionParameter)
 {
     // Set parameter metadata
     if ($reflectionParameter->isDefaultValueAvailable()) {
         $parameterDefinition->setValue($reflectionParameter->getDefaultValue());
     }
     if ($reflectionParameter->getType()) {
         $parameterDefinition->setTypeHint($reflectionParameter->getType());
     }
     $parameterDefinition->setIsOptional($reflectionParameter->isOptional());
 }
开发者ID:samsonframework,项目名称:container,代码行数:17,代码来源:ReflectionParameterAnalyzer.php

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

示例9: getType

 /**
  * @return ReflectionTypeInterface|null
  */
 public function getType()
 {
     if (PHP_MAJOR_VERSION >= 7) {
         if ($this->hasType()) {
             return new ReflectionType($this->parameter->getType());
         } else {
             return null;
         }
     }
     $type = null;
     preg_match('/\\[\\s<\\w+?>\\s([\\\\\\w]+)/', $this->parameter->__toString(), $matches);
     if (isset($matches[1])) {
         if (in_array($matches[1], ReflectionTypeInterface::NON_QUALIFIED_TYPES, true)) {
             $name = $matches[1];
         } else {
             $name = '\\' . $matches[1];
         }
         $type = new ReflectionTypePolyFill($name, $this->parameter->allowsNull());
     }
     return $type;
 }
开发者ID:hostnet,项目名称:entity-plugin-lib,代码行数:24,代码来源:ReflectionParameter.php

示例10: getType

 /**
  * Returns an associated type to the given parameter if available.
  *
  * @param \ReflectionParameter $parameter
  *
  * @return null|string
  */
 private function getType(\ReflectionParameter $parameter)
 {
     if (PHP_VERSION_ID >= 70000) {
         return $parameter->hasType() ? (string) $parameter->getType() : null;
     }
     if ($parameter->isArray()) {
         return 'array';
     }
     if ($parameter->isCallable()) {
         return 'callable';
     }
     try {
         $refClass = $parameter->getClass();
     } catch (\ReflectionException $e) {
         // mandatory; extract it from the exception message
         return str_replace(array('Class ', ' does not exist'), '', $e->getMessage());
     }
     return $refClass ? $refClass->getName() : null;
 }
开发者ID:unexge,项目名称:symfony,代码行数:26,代码来源:ArgumentMetadataFactory.php

示例11: getParameterType

 /**
  * @return string|NULL
  */
 public static function getParameterType(\ReflectionParameter $param)
 {
     if (PHP_VERSION_ID >= 70000) {
         return $param->hasType() ? (string) $param->getType() : NULL;
     } elseif ($param->isArray()) {
         return 'array';
     } elseif (PHP_VERSION_ID >= 50400 && $param->isCallable()) {
         return '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:norik16,项目名称:TripMap,代码行数:22,代码来源:PhpReflection.php

示例12: getType

 private function getType(\ReflectionParameter $parameter)
 {
     if ($this->supportsParameterType) {
         if (!($type = $parameter->getType())) {
             return;
         }
         $typeName = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString();
         if ('array' === $typeName && !$type->isBuiltin()) {
             return;
         }
         return $typeName;
     }
     if (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\\x7F-\\xFF][^ ]++)/', $parameter, $info)) {
         return $info[1];
     }
 }
开发者ID:naldz,项目名称:cyberden,代码行数:16,代码来源:classes.php

示例13: getParametersForFunction

 /**
  * @param $tmpParameter
  *
  * @return array
  */
 protected function getParametersForFunction(\ReflectionParameter $tmpParameter)
 {
     //Need to do some magic to get type of the parameter :)
     if (NULL === $tmpParameter->getClass()) {
         if ($tmpParameter->getType() != NULL) {
             $par = ['name' => $tmpParameter->getName(), 'type' => $tmpParameter->getType()];
         } else {
             $par = ['name' => $tmpParameter->getName()];
         }
         if ($tmpParameter->isDefaultValueAvailable()) {
             $par['defaultvalue'] = $tmpParameter->getDefaultValue();
             return $par;
         }
         return $par;
     } else {
         $par = ['name' => $tmpParameter->getName(), 'type' => $tmpParameter->getClass()->name];
         if ($tmpParameter->isDefaultValueAvailable()) {
             $par['defaultvalue'] = $tmpParameter->getDefaultValue();
             return $par;
         }
         return $par;
     }
 }
开发者ID:Code-Mine-Development,项目名称:CommandQueryGenerator,代码行数:28,代码来源:AbstractCommandQueryService.php

示例14: parseReflectedParams

 protected function parseReflectedParams(\ReflectionParameter $param)
 {
     $types = [];
     if ($this->canInspectReflectionParamType && (bool) ($type = $param->getType())) {
         $types[] = (string) $type;
         if ($type->allowsNull()) {
             $type[] = 'null';
         }
     }
     return ['name' => $param->getName(), 'types' => $types, 'hint' => ''];
 }
开发者ID:uuf6429,项目名称:rune,代码行数:11,代码来源:TypeAnalyser.php

示例15: getParameterType

 /**
  * @return [string, bool]
  */
 public static function getParameterType(\ReflectionParameter $param)
 {
     $def = gettype($param->isDefaultValueAvailable() ? $param->getDefaultValue() : NULL);
     if (PHP_VERSION_ID >= 70000) {
         return array((string) $param->getType() ?: $def, $param->hasType() && !$param->getType()->isBuiltin());
     } elseif ($param->isArray()) {
         return array('array', FALSE);
     } elseif (PHP_VERSION_ID >= 50400 && $param->isCallable()) {
         return array('callable', FALSE);
     } else {
         try {
             return ($ref = $param->getClass()) ? array($ref->getName(), TRUE) : array($def, FALSE);
         } catch (\ReflectionException $e) {
             if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) {
                 throw new \LogicException(sprintf("Class %s not found. Check type hint of parameter \$%s in %s() or 'use' statements.", $m[1], $param->getName(), $param->getDeclaringFunction()->getDeclaringClass()->getName() . '::' . $param->getDeclaringFunction()->getName()));
             }
             throw $e;
         }
     }
 }
开发者ID:knedle,项目名称:twitter-nette-skeleton,代码行数:23,代码来源:PresenterComponentReflection.php


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