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


PHP ReflectionParameter::isArray方法代码示例

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


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

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

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

示例3: getParameterType

 /**
  * @return string|NULL
  */
 public static function getParameterType(\ReflectionParameter $param)
 {
     if ($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:kukulich,项目名称:di,代码行数:18,代码来源:PhpReflection.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: __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: getArgument

 private static function getArgument(ReflectionParameter $parameter)
 {
     if (isset($_REQUEST[$parameter->name])) {
         if ($parameter->isArray()) {
             return $_REQUEST[$parameter->name];
         }
         $type = self::getArgumentType($parameter);
         if (!class_exists($type)) {
             throw new Exception("Type not found for attribute [{$parameter->name}]");
         }
         $object = new $type();
         if (is_array($_REQUEST[$parameter->name])) {
             foreach ($_REQUEST[$parameter->name] as $attribute => $value) {
                 $object->{$attribute} = $value;
             }
         }
         return $object;
     }
     if ($parameter->isDefaultValueAvailable()) {
         return $parameter->getDefaultValue();
     }
     if ($parameter->allowsNull()) {
         return null;
     }
     if ($parameter->isArray()) {
         return array();
     }
     $type = self::getArgumentType($parameter);
     if (!class_exists($type)) {
         throw new Exception("Type not found for attribute [{$parameter->name}]");
     }
     return new $type();
 }
开发者ID:reginaldoandrade,项目名称:ezerphp,代码行数:33,代码来源:EzerAjaxFrontController.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)
 {
     if (!$parameter->isArray()) {
         throw new \InvalidArgumentException('Provided parameter should have an array type hint');
     }
     parent::__construct($parameter);
 }
开发者ID:kamioftea,项目名称:php-util,代码行数:7,代码来源:ArrayArgument.php

示例9: isArray

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

示例10: validate

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

示例11: getTypeByReflectionParameter

 /**
  * @param \ReflectionParameter $reflectionParameter
  *
  * @return null|string
  */
 protected function getTypeByReflectionParameter(\ReflectionParameter $reflectionParameter)
 {
     if ($reflectionParameter->getClass()) {
         return $reflectionParameter->getClass()->getName();
     }
     if ($reflectionParameter->isArray()) {
         return 'array';
     }
     return null;
 }
开发者ID:jobcloud,项目名称:jobcloud-closure-validator,代码行数:15,代码来源:Validator.php

示例12: getType

 protected function getType(\ReflectionParameter $param)
 {
     if ($param->isArray()) {
         return "array";
     }
     if ($cls = $param->getClass()) {
         return $cls->getName();
     }
     return "";
 }
开发者ID:rawebone,项目名称:injector,代码行数:10,代码来源:SignatureReader.php

示例13: denormalizeParameter

 /**
  * Denormalize a method parameter value.
  *
  * @param \ReflectionParameter $reflectionParameter
  * @param mixed $value Parameter value to denormalize
  * @return mixed
  */
 protected function denormalizeParameter(\ReflectionParameter $reflectionParameter, $value)
 {
     if ($reflectionParameter->getClass() === null && !$reflectionParameter->isArray()) {
         return $value;
     }
     if (!$this->serializer instanceof DenormalizerInterface) {
         throw new LogicException('Cannot denormalize because injected serializer is not a denormalizer');
     }
     if ($reflectionParameter->getClass() !== null) {
         return $this->serializer->denormalize($value, $reflectionParameter->getClass()->name);
     }
     if ($reflectionParameter->isArray()) {
         $className = $reflectionParameter->getDeclaringClass()->getName();
         $methodName = $reflectionParameter->getDeclaringFunction()->getName();
         $parameterName = $reflectionParameter->getName();
         return $this->serializer->denormalize($value, $className . '::' . $methodName . '(' . $parameterName . ')');
     }
     return $value;
 }
开发者ID:a-mayer,项目名称:boekkooi-broadway,代码行数:26,代码来源:AdvancedInstantiationTrait.php

示例14: getTypeHint

 /**
  * Helper class for getParameterName().
  *
  * @param \ReflectionParameter $parameter
  * @return string
  */
 private static function getTypeHint(\ReflectionParameter $parameter)
 {
     if ($parameter->isArray()) {
         return 'array ';
     }
     $class = $parameter->getClass();
     if ($class) {
         return $class->getName() . ' ';
     }
     return '';
 }
开发者ID:brick,项目名称:di,代码行数:17,代码来源:UnresolvedValueException.php

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


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