mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
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.
|
||||
*
|
||||
@@ -18,22 +20,20 @@ namespace Symfony\Component\HttpKernel\ControllerMetadata;
|
||||
*/
|
||||
class ArgumentMetadata
|
||||
{
|
||||
public const IS_INSTANCEOF = 2;
|
||||
|
||||
private $name;
|
||||
private $type;
|
||||
private $isVariadic;
|
||||
private $hasDefaultValue;
|
||||
private $defaultValue;
|
||||
private $isNullable;
|
||||
private $attributes;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param bool $isVariadic
|
||||
* @param bool $hasDefaultValue
|
||||
* @param mixed $defaultValue
|
||||
* @param bool $isNullable
|
||||
* @param object[] $attributes
|
||||
*/
|
||||
public function __construct($name, $type, $isVariadic, $hasDefaultValue, $defaultValue, $isNullable = false)
|
||||
public function __construct(string $name, ?string $type, bool $isVariadic, bool $hasDefaultValue, $defaultValue, bool $isNullable = false, $attributes = [])
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
@@ -41,6 +41,13 @@ class ArgumentMetadata
|
||||
$this->hasDefaultValue = $hasDefaultValue;
|
||||
$this->defaultValue = $defaultValue;
|
||||
$this->isNullable = $isNullable || null === $type || ($hasDefaultValue && null === $defaultValue);
|
||||
|
||||
if (null === $attributes || $attributes instanceof ArgumentInterface) {
|
||||
trigger_deprecation('symfony/http-kernel', '5.3', 'The "%s" constructor expects an array of PHP attributes as last argument, %s given.', __CLASS__, get_debug_type($attributes));
|
||||
$attributes = $attributes ? [$attributes] : [];
|
||||
}
|
||||
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,4 +119,45 @@ class ArgumentMetadata
|
||||
|
||||
return $this->defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attribute (if any) that was set on the argument.
|
||||
*/
|
||||
public function getAttribute(): ?ArgumentInterface
|
||||
{
|
||||
trigger_deprecation('symfony/http-kernel', '5.3', 'Method "%s()" is deprecated, use "getAttributes()" instead.', __METHOD__);
|
||||
|
||||
if (!$this->attributes) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->attributes[0] instanceof ArgumentInterface ? $this->attributes[0] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object[]
|
||||
*/
|
||||
public function getAttributes(string $name = null, int $flags = 0): array
|
||||
{
|
||||
if (!$name) {
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
$attributes = [];
|
||||
if ($flags & self::IS_INSTANCEOF) {
|
||||
foreach ($this->attributes as $attribute) {
|
||||
if ($attribute instanceof $name) {
|
||||
$attributes[] = $attribute;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($this->attributes as $attribute) {
|
||||
if (\get_class($attribute) === $name) {
|
||||
$attributes[] = $attribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,118 +18,61 @@ namespace Symfony\Component\HttpKernel\ControllerMetadata;
|
||||
*/
|
||||
final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
|
||||
{
|
||||
/**
|
||||
* If the ...$arg functionality is available.
|
||||
*
|
||||
* Requires at least PHP 5.6.0 or HHVM 3.9.1
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $supportsVariadic;
|
||||
|
||||
/**
|
||||
* If the reflection supports the getType() method to resolve types.
|
||||
*
|
||||
* Requires at least PHP 7.0.0 or HHVM 3.11.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $supportsParameterType;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->supportsVariadic = method_exists('ReflectionParameter', 'isVariadic');
|
||||
$this->supportsParameterType = method_exists('ReflectionParameter', 'getType');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createArgumentMetadata($controller)
|
||||
public function createArgumentMetadata($controller): array
|
||||
{
|
||||
$arguments = [];
|
||||
|
||||
if (\is_array($controller)) {
|
||||
$reflection = new \ReflectionMethod($controller[0], $controller[1]);
|
||||
$class = $reflection->class;
|
||||
} elseif (\is_object($controller) && !$controller instanceof \Closure) {
|
||||
$reflection = (new \ReflectionObject($controller))->getMethod('__invoke');
|
||||
$reflection = new \ReflectionMethod($controller, '__invoke');
|
||||
$class = $reflection->class;
|
||||
} else {
|
||||
$reflection = new \ReflectionFunction($controller);
|
||||
if ($class = str_contains($reflection->name, '{closure}') ? null : $reflection->getClosureScopeClass()) {
|
||||
$class = $class->name;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($reflection->getParameters() as $param) {
|
||||
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $this->isVariadic($param), $this->hasDefaultValue($param), $this->getDefaultValue($param), $param->allowsNull());
|
||||
$attributes = [];
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
foreach ($param->getAttributes() as $reflectionAttribute) {
|
||||
if (class_exists($reflectionAttribute->getName())) {
|
||||
$attributes[] = $reflectionAttribute->newInstance();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $class), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attributes);
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether an argument is variadic.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isVariadic(\ReflectionParameter $parameter)
|
||||
{
|
||||
return $this->supportsVariadic && $parameter->isVariadic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether an argument has a default value.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasDefaultValue(\ReflectionParameter $parameter)
|
||||
{
|
||||
return $parameter->isDefaultValueAvailable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a default value if available.
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
private function getDefaultValue(\ReflectionParameter $parameter)
|
||||
{
|
||||
return $this->hasDefaultValue($parameter) ? $parameter->getDefaultValue() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an associated type to the given parameter if available.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function)
|
||||
private function getType(\ReflectionParameter $parameter, ?string $class): ?string
|
||||
{
|
||||
if ($this->supportsParameterType) {
|
||||
if (!$type = $parameter->getType()) {
|
||||
return null;
|
||||
}
|
||||
$name = $type instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
|
||||
if ('array' === $name && !$type->isBuiltin()) {
|
||||
// Special case for HHVM with variadics
|
||||
return null;
|
||||
}
|
||||
} elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $parameter, $name)) {
|
||||
$name = $name[1];
|
||||
} else {
|
||||
if (!$type = $parameter->getType()) {
|
||||
return null;
|
||||
}
|
||||
$lcName = strtolower($name);
|
||||
$name = $type instanceof \ReflectionNamedType ? $type->getName() : (string) $type;
|
||||
|
||||
if ('self' !== $lcName && 'parent' !== $lcName) {
|
||||
return $name;
|
||||
}
|
||||
if (!$function instanceof \ReflectionMethod) {
|
||||
return null;
|
||||
}
|
||||
if ('self' === $lcName) {
|
||||
return $function->getDeclaringClass()->name;
|
||||
}
|
||||
if ($parent = $function->getDeclaringClass()->getParentClass()) {
|
||||
return $parent->name;
|
||||
if (null !== $class) {
|
||||
switch (strtolower($name)) {
|
||||
case 'self':
|
||||
return $class;
|
||||
case 'parent':
|
||||
return get_parent_class($class) ?: null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Symfony\Component\HttpKernel\ControllerMetadata;
|
||||
interface ArgumentMetadataFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @param mixed $controller The controller to resolve the arguments for
|
||||
* @param string|object|array $controller The controller to resolve the arguments for
|
||||
*
|
||||
* @return ArgumentMetadata[]
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user