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


PHP ReflectionParameter::allowsNull方法代码示例

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


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

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

示例2: validate

 public function validate(\ReflectionParameter $parameter, $argument)
 {
     if ($parameter->isArray()) {
         if ($parameter->allowsNull() && is_null($argument)) {
             return;
         }
         $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:matthiasnoback,项目名称:symfony-service-definition-validator,代码行数:12,代码来源:ArgumentValidator.php

示例3: getArgConfig

 /**
  * @param Zend_Config $testConfig
  * @param ReflectionParameter $arg
  * @throws Exception
  * @throws KalturaTestException
  * @return Ambigous
  */
 protected function getArgConfig(Zend_Config $testConfig, ReflectionParameter $arg)
 {
     $argName = $arg->getName();
     $argConfig = $testConfig->get($argName);
     KalturaLog::debug("Tests data [{$argName}] config [" . print_r($argConfig, true) . "]");
     if (!$argConfig) {
         if (!$arg->allowsNull()) {
             throw new Exception("Argument [{$argName}] can't be null for test [" . $this->getName() . "]");
         }
         return null;
     }
     if (is_string($argConfig)) {
         return $argConfig;
     }
     switch ($argConfig->objectType) {
         case 'dependency':
             throw new KalturaTestException("Argument [{$argName}] taken from dependency");
         case 'array':
             return $this->populateArray($argConfig);
         case 'native':
             return $argConfig->value;
         case 'file':
             return $argConfig->path;
         default:
             return $this->populateObject($argConfig);
     }
 }
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:34,代码来源:KalturaTestCaseApiBase.php

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

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

示例6: allowsNull

 /**
  * Returns whether NULL is allowed as this parameters's value
  * @return boolean
  */
 public function allowsNull()
 {
     if ($this->parameter != null) {
         return $this->parameter->allowsNull();
     } else {
         return parent::allowsNull();
     }
 }
开发者ID:zetacomponents,项目名称:reflection,代码行数:12,代码来源:parameter.php

示例7:

 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

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

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

示例10: shouldParameterHaveAnArgument

 private function shouldParameterHaveAnArgument(\ReflectionParameter $parameter)
 {
     if ($parameter->isOptional()) {
         // any last argument with a default value is optional
         return false;
     }
     if ($parameter->isDefaultValueAvailable()) {
         // e.g. $username = 'root'
         return false;
     }
     if ($parameter->getClass() && $parameter->allowsNull()) {
         // e.g. LoggerInterface $logger = null
         return false;
     }
     return true;
 }
开发者ID:bendavies,项目名称:symfony-service-definition-validator,代码行数:16,代码来源:ArgumentsValidator.php

示例11: create_from_reflection_parameter

 public static function create_from_reflection_parameter(\ReflectionParameter $rp)
 {
     $arg = new Argument($rp->getName());
     if ($rp->allowsNull()) {
         $arg->set_null_allowed(true);
     }
     if ($rp->isDefaultValueAvailable()) {
         $arg->set_default($rp->getDefaultValue());
     }
     if ($rp->isArray()) {
         $arg->set_array(true);
     } elseif ($type = $rp->getClass()) {
         $arg->set_type($type->getName());
     }
     if ($rp->isPassedByReference()) {
         $arg->set_reference(true);
     }
     return $arg;
 }
开发者ID:jaz303,项目名称:phpx,代码行数:19,代码来源:arguments.php

示例12: getArgumentDetails

 /**
  * Gets the details for a single method argument
  *
  * @param    \ReflectionParameter $argument Argument's ReflectionParameter instance
  * @return    ArgumentData
  */
 private function getArgumentDetails(\ReflectionParameter $argument)
 {
     $details = new ArgumentData();
     $details->name = $argument->getName();
     $details->passedByReference = $argument->isPassedByReference();
     // true if no typehinting or typehinted argument defaults to null
     $details->allowsNull = $argument->allowsNull();
     $details->dataType = $this->getArgumentType($argument);
     if ($details->dataType === 'object') {
         $classData = $this->getDefaultValueClassData($argument->__toString());
         $details->className = $classData['className'];
         $details->classNamespace = $classData['classNamespace'];
     }
     if ($argument->isOptional()) {
         $details->isRequired = false;
         $details->defaultValue = $argument->getDefaultValue();
     }
     return $details;
 }
开发者ID:crimsonkissaki,项目名称:mockmaker,代码行数:25,代码来源:ArgumentDataWorker.php

示例13: argData

function argData(ReflectionParameter $arg)
{
    $details = "";
    $declaringclass = $arg->getDeclaringClass();
    $name = $arg->getName();
    $class = $arg->getClass();
    $position = $arg->getPosition();
    $details .= "\${$name} has position {$position}\n";
    if (!empty($class)) {
        $classname = $class->getName();
        $details .= "\${$name} must be a {$classname} object\n";
    }
    if ($arg->isPassedByReference()) {
        $details .= "\${$name} is passed by reference\n";
    }
    if ($arg->isDefaultValueAvailable()) {
        $def = $arg->getDefaultValue();
        $details .= "\${$name} has default: {$def}\n";
    }
    if ($arg->allowsNull()) {
        $details .= "\${$name} can be null\n";
    }
    return $details;
}
开发者ID:jabouzi,项目名称:projet,代码行数:24,代码来源:listing5.30.php

示例14: allowsNull

 /**
  * @return bool
  */
 public function allowsNull()
 {
     return $this->parameter->allowsNull();
 }
开发者ID:hostnet,项目名称:entity-plugin-lib,代码行数:7,代码来源:ReflectionParameter.php

示例15: convertParameterReflectionToArray

 /**
  * Converts the given parameter reflection into an information array
  *
  * @param ReflectionParameter $parameter The parameter to reflect
  * @return array Parameter information array
  * @author Robert Lemke <robert@typo3.org>
  * @author Sebastian Kurfürst <sebastian@typo3.org>
  */
 protected function convertParameterReflectionToArray(\ReflectionParameter $parameter, \ReflectionMethod $method = NULL)
 {
     $parameterInformation = array('position' => $parameter->getPosition(), 'byReference' => $parameter->isPassedByReference() ? TRUE : FALSE, 'array' => $parameter->isArray() ? TRUE : FALSE, 'optional' => $parameter->isOptional() ? TRUE : FALSE, 'allowsNull' => $parameter->allowsNull() ? TRUE : FALSE);
     $parameterClass = $parameter->getClass();
     $parameterInformation['class'] = $parameterClass !== NULL ? $parameterClass->getName() : NULL;
     if ($parameter->isDefaultValueAvailable()) {
         $parameterInformation['defaultValue'] = $parameter->getDefaultValue();
     }
     if ($parameterClass !== NULL) {
         $parameterInformation['type'] = ltrim($parameterClass->getName(), '\\');
     } elseif ($method !== NULL) {
         $methodTagsAndValues = $this->getMethodTagsValues($method->getDeclaringClass()->getName(), $method->getName());
         if (isset($methodTagsAndValues['param']) && isset($methodTagsAndValues['param'][$parameter->getPosition()])) {
             $explodedParameters = explode(' ', $methodTagsAndValues['param'][$parameter->getPosition()]);
             if (count($explodedParameters) >= 2) {
                 $parameterInformation['type'] = ltrim($explodedParameters[0], '\\');
             }
         }
     }
     return $parameterInformation;
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:29,代码来源:ReflectionService.php


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