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


PHP ReflectionParameter::hasType方法代码示例

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


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

示例1: hasType

 /**
  * @return bool
  */
 public function hasType()
 {
     if (method_exists($this->parameter, 'getType')) {
         return $this->parameter->hasType();
     }
     return null !== $this->getType();
 }
开发者ID:hostnet,项目名称:entity-plugin-lib,代码行数:10,代码来源:ReflectionParameter.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: 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

示例4: 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() || $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:Northys,项目名称:di,代码行数:20,代码来源:PhpReflection.php

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

示例6: hasType

 /**
  * @param  ReflectionParameter $parameter
  *
  * @return boolean
  * @since  Method available since Release 2.3.4
  */
 private function hasType(ReflectionParameter $parameter)
 {
     return method_exists('ReflectionParameter', 'hasType') && $parameter->hasType();
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:10,代码来源:Generator.php

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

示例8: testGetTypeMethod

 public function testGetTypeMethod()
 {
     if (PHP_VERSION_ID < 70000) {
         $this->markTestSkipped('Test available only for PHP7.0 and newer');
     }
     foreach ($this->parsedRefFile->getFileNamespaces() as $fileNamespace) {
         foreach ($fileNamespace->getFunctions() as $refFunction) {
             $functionName = $refFunction->getName();
             foreach ($refFunction->getParameters() as $refParameter) {
                 $parameterName = $refParameter->getName();
                 $originalRefParameter = new \ReflectionParameter($functionName, $parameterName);
                 $hasType = $refParameter->hasType();
                 $this->assertSame($originalRefParameter->hasType(), $hasType, "Presence of type for parameter {$functionName}:{$parameterName} should be equal");
                 if ($hasType) {
                     $parsedReturnType = $refParameter->getType();
                     $originalReturnType = $originalRefParameter->getType();
                     $this->assertSame($originalReturnType->allowsNull(), $parsedReturnType->allowsNull());
                     $this->assertSame($originalReturnType->isBuiltin(), $parsedReturnType->isBuiltin());
                     $this->assertSame($originalReturnType->__toString(), $parsedReturnType->__toString());
                 } else {
                     $this->assertSame($originalRefParameter->getType(), $refParameter->getType());
                 }
             }
         }
     }
 }
开发者ID:goaop,项目名称:parser-reflection,代码行数:26,代码来源:ReflectionParameterTest.php

示例9: testHasType

 public function testHasType()
 {
     $php_parameter = new \ReflectionParameter([$this, 'method'], 'param');
     $our_parameter = new ReflectionParameter($php_parameter);
     $this->assertTrue($our_parameter->hasType());
 }
开发者ID:hostnet,项目名称:entity-plugin-lib,代码行数:6,代码来源:ReflectionParameterTest.php

示例10: determineParameterValue

 public function determineParameterValue(\ReflectionParameter $parameter, Constructor\Parameter\ParameterInterface $configuredParameter = null, array $values = [])
 {
     # extract relevant info from the ReflectionParameter.
     $name = $parameter->getName();
     $type = $parameter->hasType() === true ? $parameter->getType()->__toString() : 'string';
     $isConstructable = class_exists($type) || interface_exists($type);
     $default = $parameter->isDefaultValueAvailable() === true ? $parameter->getDefaultValue() : null;
     $position = $parameter->getPosition();
     # if there's a configured parameter, use this first
     if (is_null($configuredParameter) === false) {
         return $configuredParameter->getValue($this);
     }
     # if a value was passed in by ordinal position in the values array, use this next
     if (isset($values[$position]) === true) {
         return $values[$position];
     }
     # if a value was passed in by name in the values array, use this next
     if (isset($values[$name]) === true) {
         return $values[$name];
     }
     if ($this->has($name) === true) {
         return $this->get($name);
     }
     # if this is not a constructable value and it's in the container by name, use that value
     if ($isConstructable === false && $this->has($name) === true) {
         return $this->get($name);
     }
     # if it's constructable, see if we have a constructor defined for it.
     if ($isConstructable === true) {
         $constructor = $this->findConstructor($name, $type);
         # if we still haven't found a way to construct it, but it *is* in theory
         # constructable, add a new constructor for it and hope everything works out.
         if ($constructor === false) {
             #echo("Constructing a new name=$name,type=$type\n");
             $constructor = new Constructor\Constructor($type, $type, false);
             $this->addConstructor($constructor);
         }
         $this->_debug("Constructing parameter value {$name}/{$type}.");
         return $this->construct($name, $type, $constructor);
     }
     return $default;
 }
开发者ID:dev-lucid,项目名称:container,代码行数:42,代码来源:InjectorFactoryContainer.php


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