N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)

* Update Symfony lib to version ~6.4.0
* Update code missing return type
* Add an iTop general configuration entry to store application secret (Symfony mandatory parameter)
* Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
bdalsass
2023-12-05 13:56:56 +01:00
committed by GitHub
parent 863ab4560c
commit 27ce51ab07
1392 changed files with 44869 additions and 27799 deletions

View File

@@ -11,42 +11,15 @@
namespace Symfony\Bundle\FrameworkBundle\Routing;
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
use Symfony\Component\Routing\Route;
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', AnnotatedRouteControllerLoader::class, AttributeRouteControllerLoader::class);
/**
* AnnotatedRouteControllerLoader is an implementation of AnnotationClassLoader
* that sets the '_controller' default based on the class and method names.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class AnnotatedRouteControllerLoader extends AnnotationClassLoader
{
class_exists(AttributeRouteControllerLoader::class);
if (false) {
/**
* Configures the _controller default parameter of a given Route instance.
* @deprecated since Symfony 6.4, to be removed in 7.0, use {@link AttributeRouteControllerLoader} instead
*/
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot)
class AnnotatedRouteControllerLoader
{
if ('__invoke' === $method->getName()) {
$route->setDefault('_controller', $class->getName());
} else {
$route->setDefault('_controller', $class->getName().'::'.$method->getName());
}
}
/**
* Makes the default route name more sane by removing common keywords.
*
* @return string
*/
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
{
$name = preg_replace('/(bundle|controller)_/', '_', parent::getDefaultRouteName($class, $method));
if (str_ends_with($method->name, 'Action') || str_ends_with($method->name, '_action')) {
$name = preg_replace('/action(_\d+)?$/', '\\1', $name);
}
return str_replace('__', '_', $name);
}
}

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Routing\Attribute;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
/**
* Service tag to autoconfigure routing condition services.
*
* You can tag a service:
*
* #[AsRoutingConditionService('foo')]
* class SomeFooService
* {
* public function bar(): bool
* {
* // ...
* }
* }
*
* Then you can use the tagged service in the routing condition:
*
* class PageController
* {
* #[Route('/page', condition: "service('foo').bar()")]
* public function page(): Response
* {
* // ...
* }
* }
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
class AsRoutingConditionService extends AutoconfigureTag
{
public function __construct(
string $alias = null,
int $priority = 0,
) {
parent::__construct('routing.condition_service', ['alias' => $alias, 'priority' => $priority]);
}
}

View File

@@ -0,0 +1,57 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Routing;
use Symfony\Component\Routing\Loader\AttributeClassLoader;
use Symfony\Component\Routing\Route;
/**
* AttributeRouteControllerLoader is an implementation of AttributeClassLoader
* that sets the '_controller' default based on the class and method names.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Alexandre Daubois <alex.daubois@gmail.com>
*/
class AttributeRouteControllerLoader extends AttributeClassLoader
{
/**
* Configures the _controller default parameter of a given Route instance.
*
* @return void
*/
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot)
{
if ('__invoke' === $method->getName()) {
$route->setDefault('_controller', $class->getName());
} else {
$route->setDefault('_controller', $class->getName().'::'.$method->getName());
}
}
/**
* Makes the default route name more sane by removing common keywords.
*/
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method): string
{
$name = preg_replace('/(bundle|controller)_/', '_', parent::getDefaultRouteName($class, $method));
if (str_ends_with($method->name, 'Action') || str_ends_with($method->name, '_action')) {
$name = preg_replace('/action(_\d+)?$/', '\\1', $name);
}
return str_replace('__', '_', $name);
}
}
if (!class_exists(AnnotatedRouteControllerLoader::class, false)) {
class_alias(AttributeRouteControllerLoader::class, AnnotatedRouteControllerLoader::class);
}

View File

@@ -28,9 +28,9 @@ use Symfony\Component\Routing\RouteCollection;
*/
class DelegatingLoader extends BaseDelegatingLoader
{
private $loading = false;
private $defaultOptions;
private $defaultRequirements;
private bool $loading = false;
private array $defaultOptions;
private array $defaultRequirements;
public function __construct(LoaderResolverInterface $resolver, array $defaultOptions = [], array $defaultRequirements = [])
{
@@ -40,10 +40,7 @@ class DelegatingLoader extends BaseDelegatingLoader
parent::__construct($resolver);
}
/**
* {@inheritdoc}
*/
public function load($resource, string $type = null): RouteCollection
public function load(mixed $resource, string $type = null): RouteCollection
{
if ($this->loading) {
// This can happen if a fatal error occurs in parent::load().
@@ -58,7 +55,7 @@ class DelegatingLoader extends BaseDelegatingLoader
// the fatal error from occurring a second time,
// otherwise the PHP process would be killed immediately;
// - while rendering the exception page, the router can be required
// (by e.g. the web profiler that needs to generate an URL);
// (by e.g. the web profiler that needs to generate a URL);
// - this handles the case and prevents the second fatal error
// by triggering an exception beforehand.

View File

@@ -21,9 +21,6 @@ use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
*/
class RedirectableCompiledUrlMatcher extends CompiledUrlMatcher implements RedirectableUrlMatcherInterface
{
/**
* {@inheritdoc}
*/
public function redirect(string $path, string $route, string $scheme = null): array
{
return [

View File

@@ -33,14 +33,14 @@ use Symfony\Contracts\Service\ServiceSubscriberInterface;
*/
class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberInterface
{
private $container;
private $collectedParameters = [];
private $paramFetcher;
private ContainerInterface $container;
private array $collectedParameters = [];
private \Closure $paramFetcher;
/**
* @param mixed $resource The main resource to load
*/
public function __construct(ContainerInterface $container, $resource, array $options = [], RequestContext $context = null, ContainerInterface $parameters = null, LoggerInterface $logger = null, string $defaultLocale = null)
public function __construct(ContainerInterface $container, mixed $resource, array $options = [], RequestContext $context = null, ContainerInterface $parameters = null, LoggerInterface $logger = null, string $defaultLocale = null)
{
$this->container = $container;
$this->resource = $resource;
@@ -49,9 +49,9 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
$this->setOptions($options);
if ($parameters) {
$this->paramFetcher = \Closure::fromCallable([$parameters, 'get']);
$this->paramFetcher = $parameters->get(...);
} elseif ($container instanceof SymfonyContainerInterface) {
$this->paramFetcher = \Closure::fromCallable([$container, 'getParameter']);
$this->paramFetcher = $container->getParameter(...);
} else {
throw new \LogicException(sprintf('You should either pass a "%s" instance or provide the $parameters argument of the "%s" method.', SymfonyContainerInterface::class, __METHOD__));
}
@@ -59,12 +59,9 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
$this->defaultLocale = $defaultLocale;
}
/**
* {@inheritdoc}
*/
public function getRouteCollection()
public function getRouteCollection(): RouteCollection
{
if (null === $this->collection) {
if (!isset($this->collection)) {
$this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);
$this->resolveParameters($this->collection);
$this->collection->addResource(new ContainerParametersResource($this->collectedParameters));
@@ -76,7 +73,7 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
} else {
$this->collection->addResource(new FileExistenceResource($containerFile));
}
} catch (ParameterNotFoundException $exception) {
} catch (ParameterNotFoundException) {
}
}
@@ -84,11 +81,9 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
}
/**
* {@inheritdoc}
*
* @return string[] A list of classes to preload on PHP 7.4+
* @param string|null $buildDir
*/
public function warmUp(string $cacheDir)
public function warmUp(string $cacheDir /* , string $buildDir = null */): array
{
$currentDir = $this->getOption('cache_dir');
@@ -114,7 +109,7 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
* - the route schemes,
* - the route methods.
*/
private function resolveParameters(RouteCollection $collection)
private function resolveParameters(RouteCollection $collection): void
{
foreach ($collection as $route) {
foreach ($route->getDefaults() as $name => $value) {
@@ -144,17 +139,12 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
}
/**
* Recursively replaces placeholders with the service container parameters.
*
* @param mixed $value The source which might contain "%placeholders%"
*
* @return mixed The source with the placeholders replaced by the container
* parameters. Arrays are resolved recursively.
* Recursively replaces %placeholders% with the service container parameters.
*
* @throws ParameterNotFoundException When a placeholder does not exist as a container parameter
* @throws RuntimeException When a container value is not a string or a numeric value
*/
private function resolve($value)
private function resolve(mixed $value): mixed
{
if (\is_array($value)) {
foreach ($value as $key => $val) {
@@ -198,10 +188,7 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
return str_replace('%%', '%', $escapedValue);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedServices()
public static function getSubscribedServices(): array
{
return [
'routing.loader' => LoaderInterface::class,