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


PHP ReflectionParameter::isDefaultValueAvailable方法代码示例

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

在下文中一共展示了ReflectionParameter::isDefaultValueAvailable方法的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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: 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


示例4: exportCode

 public function exportCode()
 {
     $default_value = null;
     if ($this->_parameter->isDefaultValueAvailable()) {
         $default_value = $this->_parameter->getDefaultValue();
         if (is_scalar($default_value) && !is_numeric($default_value)) {
             $default_value = "'{$default_value}'";
         }
     } elseif ($this->_parameter->isOptional()) {
         $default_value = 'NULL';
     }
     return sprintf('%s%s$%s%s', $this->_parameter->getClass() ? "{$this->_parameter->getClass()->getName()} " : '', $this->_parameter->isPassedByReference() ? '&' : '', $this->_parameter->getName(), $default_value ? " = {$default_value}" : '');
 }
开发者ID:michalkoslab,项目名称:Helpers,代码行数:13,代码来源:ReflectionParameter.php


示例5: getParameterValue

 /**
  * {@inheritdoc}
  */
 public function getParameterValue(\ReflectionParameter $parameter)
 {
     if ($parameter->isDefaultValueAvailable()) {
         return $parameter->getDefaultValue();
     }
     throw UnresolvedValueException::unresolvedParameter($parameter);
 }
开发者ID:brick,项目名称:di,代码行数:10,代码来源:DefaultValueResolver.php


示例6: testGeneralInfoGetters

 public function testGeneralInfoGetters()
 {
     $allNameGetters = ['isArray', 'isCallable', 'isOptional', 'isPassedByReference', 'isDefaultValueAvailable', 'getPosition', 'canBePassedByValue', 'allowsNull', 'getDefaultValue', 'getDefaultValueConstantName', 'isDefaultValueConstant', '__toString'];
     $onlyWithDefaultValues = array_flip(['getDefaultValue', 'getDefaultValueConstantName', 'isDefaultValueConstant']);
     if (PHP_VERSION_ID >= 50600) {
         $allNameGetters[] = 'isVariadic';
     }
     if (PHP_VERSION_ID >= 70000) {
         $allNameGetters[] = 'hasType';
     }
     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);
                 foreach ($allNameGetters as $getterName) {
                     // skip some methods if there is no default value
                     $isDefaultValueAvailable = $originalRefParameter->isDefaultValueAvailable();
                     if (isset($onlyWithDefaultValues[$getterName]) && !$isDefaultValueAvailable) {
                         continue;
                     }
                     $expectedValue = $originalRefParameter->{$getterName}();
                     $actualValue = $refParameter->{$getterName}();
                     $this->assertSame($expectedValue, $actualValue, "{$getterName}() for parameter {$functionName}:{$parameterName} should be equal");
                 }
             }
         }
     }
 }
开发者ID:goaop,项目名称:parser-reflection,代码行数:30,代码来源:ReflectionParameterTest.php


示例7: fromReflection

 /**
  * Creates a PHP parameter from reflection
  * 
  * @param \ReflectionParameter $ref
  * @return PhpParameter
  */
 public static function fromReflection(\ReflectionParameter $ref)
 {
     $parameter = new static();
     $parameter->setName($ref->name)->setPassedByReference($ref->isPassedByReference());
     if ($ref->isDefaultValueAvailable()) {
         $parameter->setDefaultValue($ref->getDefaultValue());
     }
     // find type and description in docblock
     $docblock = new Docblock($ref->getDeclaringFunction());
     $params = $docblock->getTags('param');
     $tag = $params->find($ref->name, function (ParamTag $t, $name) {
         return $t->getVariable() == '$' . $name;
     });
     if ($tag !== null) {
         $parameter->setType($tag->getType(), $tag->getDescription());
     }
     // set type if not found in comment
     if ($parameter->getType() === null) {
         if ($ref->isArray()) {
             $parameter->setType('array');
         } elseif ($class = $ref->getClass()) {
             $parameter->setType($class->getName());
         } elseif (method_exists($ref, 'isCallable') && $ref->isCallable()) {
             $parameter->setType('callable');
         }
     }
     return $parameter;
 }
开发者ID:domagala,项目名称:php-code-generator,代码行数:34,代码来源:PhpParameter.php


示例8: __construct

 public function __construct(\ReflectionParameter $parameter)
 {
     $this->name = $parameter->getName();
     $this->position = $parameter->getPosition();
     $this->has_default = $parameter->isDefaultValueAvailable();
     $this->default_value = $this->getHasDefault() ? $parameter->getDefaultValue() : null;
 }
开发者ID:kamioftea,项目名称:php-util,代码行数:7,代码来源:Argument.php


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


示例10: resolveNonClass

 /**
  * @param ReflectionParameter $parameter
  * @return mixed
  * @throws Exception
  */
 public function resolveNonClass($parameter)
 {
     // 有默认值则返回默认值
     if ($parameter->isDefaultValueAvailable()) {
         return $parameter->getDefaultValue();
     }
     throw new Exception('I have no idea what to do here.');
 }
开发者ID:TeamOfMalaysia,项目名称:H,代码行数:13,代码来源:Container.php


示例11: isDefaultValueAvailable

 /**
  * Returns whether the default value of this parameter is available
  * @return boolean
  * @since PHP 5.0.3
  */
 public function isDefaultValueAvailable()
 {
     if ($this->parameter != null) {
         return $this->parameter->isDefaultValueAvailable();
     } else {
         return parent::isDefaultValueAvailable();
     }
 }
开发者ID:zetacomponents,项目名称:reflection,代码行数:13,代码来源:parameter.php


示例12: getDefaultValue

 private function getDefaultValue(\ReflectionParameter $parameter)
 {
     $defaultValue = null;
     if ($parameter->isDefaultValueAvailable()) {
         $defaultValue = $parameter->getDefaultValue();
     }
     return $defaultValue;
 }
开发者ID:steve-rodrigue,项目名称:entity-apis,代码行数:8,代码来源:ConcreteEntityAdapter.php


示例13: _createFromReflection

 /**
  * @load
  * @param ReflectionParameter $reflection
  */
 private function _createFromReflection($reflection)
 {
     $this->_name = $reflection->getName();
     if ($reflection->isDefaultValueAvailable()) {
         $this->_default = true;
         $this->_value = $reflection->getDefaultValue();
     }
 }
开发者ID:neel,项目名称:bong,代码行数:12,代码来源:Argument.php


示例14:

 function __construct(API_Doc_Method $method, ReflectionParameter $parameter)
 {
     $this->name = $parameter->getName();
     $this->is_passed_by_reference = $parameter->isPassedByReference();
     $this->allows_null = $parameter->allowsNull();
     $this->is_optional = $parameter->isOptional();
     $this->is_default_value_available = $parameter->isDefaultValueAvailable();
     $this->position = $parameter->getPosition();
     $this->declaring_method = $method;
 }
开发者ID:Debenson,项目名称:openwan,代码行数:10,代码来源:parameter.php


示例15: testWrappedMethods

 public function testWrappedMethods()
 {
     $php_parameter = new \ReflectionParameter([$this, 'method'], 'param');
     $our_parameter = new ReflectionParameter($php_parameter);
     $this->assertSame($php_parameter->getName(), $our_parameter->getName());
     $this->assertSame($php_parameter->allowsNull(), $our_parameter->allowsNull());
     $this->assertSame($php_parameter->isOptional(), $our_parameter->isOptional());
     $this->assertSame($php_parameter->isDefaultValueAvailable(), $our_parameter->isDefaultValueAvailable());
     $this->assertSame($php_parameter->isVariadic(), $our_parameter->isVariadic());
     $this->assertSame($php_parameter->isPassedByReference(), $our_parameter->isPassedByReference());
     $this->assertSame($php_parameter->getDefaultValue(), $our_parameter->getDefaultValue());
 }
开发者ID:hostnet,项目名称:entity-plugin-lib,代码行数:12,代码来源:ReflectionParameterTest.php


示例16: extractDefaultValue

 /**
  * @param \ReflectionParameter $parameter
  * @return mixed|null
  */
 private function extractDefaultValue(\ReflectionParameter $parameter)
 {
     if ($parameter->isDefaultValueAvailable()) {
         $value = $parameter->getDefaultValue();
     } else {
         return null;
     }
     if (empty($value) || !is_array($value)) {
         $value = null;
     }
     return $value;
 }
开发者ID:angrybender,项目名称:phpPM,代码行数:16,代码来源:ParserMethodCall.php


示例17: fillParameter

 /**
  * Setup arguments for current action
  *
  * @param \ReflectionParameter $Parameter
  *
  * @return array
  */
 public function fillParameter(\ReflectionParameter $Parameter)
 {
     $UrlParts = Application::$i->URL->parts();
     if (!isset($UrlParts[$Parameter->getPosition() + 2])) {
         if ($Parameter->isDefaultValueAvailable() === false) {
             showError('Parameter $' . $Parameter->getName() . ' not found');
         }
         $value = $Parameter->getDefaultValue();
     } else {
         $value = Application::$i->URL->parts($Parameter->getPosition() + 2);
     }
     return $value;
 }
开发者ID:RomanAngelovskij,项目名称:framework,代码行数:20,代码来源:Routes.php


示例18: isDefaultValueAvailable

 /**
  * @return bool
  */
 public function isDefaultValueAvailable()
 {
     if (PHP_VERSION_ID === 50316) {
         // PHP bug #62988
         try {
             $this->getDefaultValue();
             return TRUE;
         } catch (ReflectionException $e) {
             return FALSE;
         }
     }
     return parent::isDefaultValueAvailable();
 }
开发者ID:riskatlas,项目名称:micka,代码行数:16,代码来源:Parameter.php


示例19: resolveParameter

 protected function resolveParameter($parameters, \ReflectionParameter $constructorArg)
 {
     $parameterName = $constructorArg->getName();
     $parameterPosition = $constructorArg->getPosition();
     if (isset($parameters[$parameterName])) {
         return $parameters[$parameterName];
     } else {
         if (isset($parameters[$parameterPosition])) {
             return $parameters[$parameterPosition];
         } else {
             if (isset($this->parameters[$parameterName])) {
                 return $this->parameters[$parameterName];
             } else {
                 if (isset($this->parameters[$parameterPosition])) {
                     return $this->parameters[$parameterPosition];
                 } else {
                     if ($constructorArg->getClass() !== null) {
                         try {
                             return $this->factory->get($constructorArg->getClass()->getName());
                         } catch (InstantiationException $e) {
                             if ($constructorArg->isDefaultValueAvailable()) {
                                 return $constructorArg->getDefaultValue();
                             } else {
                                 throw $e;
                             }
                         }
                     } else {
                         if ($constructorArg->isDefaultValueAvailable()) {
                             return $constructorArg->getDefaultValue();
                         } else {
                             throw new ParameterMissingException($parameterName);
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:bugadani,项目名称:factory,代码行数:38,代码来源:Constructor.php


示例20: parameter

 /**
  * @param \ReflectionParameter $parameter
  * @return Parameter
  */
 public function parameter(\ReflectionParameter $parameter)
 {
     $phpyParam = new Parameter($parameter->getName());
     if ($parameter->isArray()) {
         $phpyParam->setTypeHint('array');
     } elseif ($class = $parameter->getClass()) {
         $phpyParam->setTypeHint('\\' . $class->getName());
     }
     if ($parameter->isDefaultValueAvailable()) {
         $phpyParam->setDefaultValue($parameter->getDefaultValue());
     }
     $phpyParam->setByRef($parameter->isPassedByReference());
     return $phpyParam;
 }
开发者ID:nicmart,项目名称:phpy,代码行数:18,代码来源:PhpyFactory.php



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