本文整理汇总了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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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);
}
}
示例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();
}
示例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;
}
示例8: __construct
public function __construct(\ReflectionParameter $parameter)
{
if (!$parameter->isArray()) {
throw new \InvalidArgumentException('Provided parameter should have an array type hint');
}
parent::__construct($parameter);
}
示例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();
}
}
示例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
}
示例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;
}
示例12: getType
protected function getType(\ReflectionParameter $param)
{
if ($param->isArray()) {
return "array";
}
if ($cls = $param->getClass()) {
return $cls->getName();
}
return "";
}
示例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;
}
示例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 '';
}
示例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;
}
}
}