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


PHP ReflectionParameter::isOptional方法代码示例

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


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

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

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

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

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

 protected function getParam(\ReflectionParameter $param)
 {
     $name = $param->getName();
     if (!isset($this->args['params'][$name]) && !$param->isOptional()) {
         $message = sprintf('You must define param "%s" for "%s"', $name, $this->args['class']);
         throw new \OutOfBoundsException($message);
     }
     if (!isset($this->args['params'][$name]) && $param->isOptional()) {
         return $param->getDefaultValue();
     }
     $value = $this->args['params'][$name];
     $param = is_string($value) && defined($value) ? constant($value) : $value;
     return $param;
 }
开发者ID:dafiti,项目名称:logger-service-provider,代码行数:14,代码来源:AbstractFactory.php

示例6: checkArgument

 protected function checkArgument(ReflectionParameter $argument, $i)
 {
     if ($argument->isOptional() == false && !isset(Request::$get[$i])) {
         self::jump(400);
     }
     return $argument;
 }
开发者ID:rlt3,项目名称:Stream,代码行数:7,代码来源:View.php

示例7: isOptional

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

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

示例9:

 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

示例10: __construct

 protected function __construct(\ReflectionParameter $parameter, $overridenValue)
 {
     if (!$overridenValue instanceof MissingParameter && !$overridenValue instanceof DefaultParameter) {
         $this->setDefaultValue($overridenValue);
     } else {
         if ($parameter && $parameter->isOptional()) {
             $this->setDefaultValue($parameter->getDefaultValue());
         }
     }
 }
开发者ID:conpago,项目名称:conpago-di,代码行数:10,代码来源:CustomParameter.php

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

示例12: getParameterExtraValue

 protected function getParameterExtraValue(\ReflectionParameter $parameter)
 {
     if (empty($this->extraValues)) {
         if ($parameter->isOptional()) {
             return $parameter->getDefaultValue();
         } else {
             throw new Exception("");
         }
     } else {
         return array_pop($extras);
     }
 }
开发者ID:panlatent,项目名称:container,代码行数:12,代码来源:Injector.php

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

示例14: addParameter

 /**
  * @param \ReflectionParameter $parameter
  * @param string $description
  */
 public function addParameter(\ReflectionParameter $parameter, $description)
 {
     $name = $parameter->getName();
     if (!$parameter->isOptional()) {
         $this->addArgument($name, InputArgument::REQUIRED, $description);
         return;
     }
     if ($this->isFlagOption($parameter)) {
         $this->addOption($name, null, InputOption::VALUE_NONE, $description);
         return;
     }
     $default = $parameter->getDefaultValue();
     $this->addArgument($name, InputArgument::OPTIONAL, $description, $default);
 }
开发者ID:Catapush,项目名称:Idephix,代码行数:18,代码来源:CommandWrapper.php

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


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