upgrade to laravel 7 and set branch to v2
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\ControllerMetadata;
|
||||
|
||||
use Symfony\Component\HttpKernel\Attribute\ArgumentInterface;
|
||||
|
||||
/**
|
||||
* Responsible for storing metadata of an argument.
|
||||
*
|
||||
@@ -24,8 +26,9 @@ class ArgumentMetadata
|
||||
private $hasDefaultValue;
|
||||
private $defaultValue;
|
||||
private $isNullable;
|
||||
private $attribute;
|
||||
|
||||
public function __construct(string $name, ?string $type, bool $isVariadic, bool $hasDefaultValue, $defaultValue, bool $isNullable = false)
|
||||
public function __construct(string $name, ?string $type, bool $isVariadic, bool $hasDefaultValue, $defaultValue, bool $isNullable = false, ?ArgumentInterface $attribute = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
@@ -33,6 +36,7 @@ class ArgumentMetadata
|
||||
$this->hasDefaultValue = $hasDefaultValue;
|
||||
$this->defaultValue = $defaultValue;
|
||||
$this->isNullable = $isNullable || null === $type || ($hasDefaultValue && null === $defaultValue);
|
||||
$this->attribute = $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,4 +108,12 @@ class ArgumentMetadata
|
||||
|
||||
return $this->defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attribute (if any) that was set on the argument.
|
||||
*/
|
||||
public function getAttribute(): ?ArgumentInterface
|
||||
{
|
||||
return $this->attribute;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\ControllerMetadata;
|
||||
|
||||
use Symfony\Component\HttpKernel\Attribute\ArgumentInterface;
|
||||
use Symfony\Component\HttpKernel\Exception\InvalidMetadataException;
|
||||
|
||||
/**
|
||||
* Builds {@see ArgumentMetadata} objects based on the given Controller.
|
||||
*
|
||||
@@ -34,7 +37,28 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
|
||||
}
|
||||
|
||||
foreach ($reflection->getParameters() as $param) {
|
||||
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull());
|
||||
$attribute = null;
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
$reflectionAttributes = $param->getAttributes(ArgumentInterface::class, \ReflectionAttribute::IS_INSTANCEOF);
|
||||
|
||||
if (\count($reflectionAttributes) > 1) {
|
||||
$representative = $controller;
|
||||
|
||||
if (\is_array($representative)) {
|
||||
$representative = sprintf('%s::%s()', \get_class($representative[0]), $representative[1]);
|
||||
} elseif (\is_object($representative)) {
|
||||
$representative = \get_class($representative);
|
||||
}
|
||||
|
||||
throw new InvalidMetadataException(sprintf('Controller "%s" has more than one attribute for "$%s" argument.', $representative, $param->getName()));
|
||||
}
|
||||
|
||||
if (isset($reflectionAttributes[0])) {
|
||||
$attribute = $reflectionAttributes[0]->newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attribute);
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
|
||||
Reference in New Issue
Block a user