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:
bdalsass
2022-06-16 09:13:24 +02:00
committed by GitHub
parent abb13b70b9
commit 79da71ecf8
2178 changed files with 87439 additions and 59451 deletions

View File

@@ -24,10 +24,8 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader
{
/**
* Configures the _controller default parameter of a given Route instance.
*
* @param mixed $annot The annotation class instance
*/
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot)
{
if ('__invoke' === $method->getName()) {
$route->setDefault('_controller', $class->getName());
@@ -43,14 +41,12 @@ class AnnotatedRouteControllerLoader extends AnnotationClassLoader
*/
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
{
return preg_replace([
'/(bundle|controller)_/',
'/action(_\d+)?$/',
'/__/',
], [
'_',
'\\1',
'_',
], parent::getDefaultRouteName($class, $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

@@ -11,10 +11,10 @@
namespace Symfony\Bundle\FrameworkBundle\Routing;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Component\Config\Exception\FileLoaderLoadException;
use Symfony\Component\Config\Exception\LoaderLoadException;
use Symfony\Component\Config\Loader\DelegatingLoader as BaseDelegatingLoader;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\Routing\RouteCollection;
/**
* DelegatingLoader delegates route loading to other loaders using a loader resolver.
@@ -23,19 +23,19 @@ use Symfony\Component\Config\Loader\LoaderResolverInterface;
* to the fully-qualified form (from a:b:c to class::method).
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @final
*/
class DelegatingLoader extends BaseDelegatingLoader
{
protected $parser;
private $loading = false;
private $defaultOptions;
private $defaultRequirements;
/**
* @param ControllerNameParser $parser A ControllerNameParser instance
* @param LoaderResolverInterface $resolver A LoaderResolverInterface instance
*/
public function __construct(ControllerNameParser $parser, LoaderResolverInterface $resolver)
public function __construct(LoaderResolverInterface $resolver, array $defaultOptions = [], array $defaultRequirements = [])
{
$this->parser = $parser;
$this->defaultOptions = $defaultOptions;
$this->defaultRequirements = $defaultRequirements;
parent::__construct($resolver);
}
@@ -43,7 +43,7 @@ class DelegatingLoader extends BaseDelegatingLoader
/**
* {@inheritdoc}
*/
public function load($resource, $type = null)
public function load($resource, string $type = null): RouteCollection
{
if ($this->loading) {
// This can happen if a fatal error occurs in parent::load().
@@ -62,7 +62,7 @@ class DelegatingLoader extends BaseDelegatingLoader
// - this handles the case and prevents the second fatal error
// by triggering an exception beforehand.
throw new FileLoaderLoadException($resource, null, null, null, $type);
throw new LoaderLoadException($resource, null, 0, null, $type);
}
$this->loading = true;
@@ -73,14 +73,18 @@ class DelegatingLoader extends BaseDelegatingLoader
}
foreach ($collection->all() as $route) {
if (!\is_string($controller = $route->getDefault('_controller')) || !$controller) {
if ($this->defaultOptions) {
$route->setOptions($route->getOptions() + $this->defaultOptions);
}
if ($this->defaultRequirements) {
$route->setRequirements($route->getRequirements() + $this->defaultRequirements);
}
if (!\is_string($controller = $route->getDefault('_controller'))) {
continue;
}
try {
$controller = $this->parser->parse($controller);
} catch (\InvalidArgumentException $e) {
// unable to optimize unknown notation
if (str_contains($controller, '::')) {
continue;
}
$route->setDefault('_controller', $controller);

View File

@@ -11,23 +11,20 @@
namespace Symfony\Bundle\FrameworkBundle\Routing;
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcher as BaseMatcher;
use Symfony\Component\Routing\Matcher\CompiledUrlMatcher;
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
/**
* @author Fabien Potencier <fabien@symfony.com>
*
* @internal
*/
class RedirectableUrlMatcher extends BaseMatcher
class RedirectableCompiledUrlMatcher extends CompiledUrlMatcher implements RedirectableUrlMatcherInterface
{
/**
* Redirects the user to another URL.
*
* @param string $path The path info to redirect to
* @param string $route The route that matched
* @param string $scheme The URL scheme (null to keep the current one)
*
* @return array An array of parameters
* {@inheritdoc}
*/
public function redirect($path, $route, $scheme = null)
public function redirect(string $path, string $route, string $scheme = null): array
{
return [
'_controller' => 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction',

View File

@@ -0,0 +1,19 @@
<?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;
/**
* Marker interface for service route loaders.
*/
interface RouteLoaderInterface
{
}

View File

@@ -11,16 +11,20 @@
namespace Symfony\Bundle\FrameworkBundle\Routing;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileExistenceResource;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\Config\ContainerParametersResource;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Router as BaseRouter;
use Symfony\Contracts\Service\ServiceSubscriberInterface;
/**
* This Router creates the Loader only when the cache is empty.
@@ -31,20 +35,28 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
{
private $container;
private $collectedParameters = [];
private $paramFetcher;
/**
* @param ContainerInterface $container A ContainerInterface instance
* @param mixed $resource The main resource to load
* @param array $options An array of options
* @param RequestContext $context The context
* @param mixed $resource The main resource to load
*/
public function __construct(ContainerInterface $container, $resource, array $options = [], RequestContext $context = null)
public function __construct(ContainerInterface $container, $resource, array $options = [], RequestContext $context = null, ContainerInterface $parameters = null, LoggerInterface $logger = null, string $defaultLocale = null)
{
$this->container = $container;
$this->resource = $resource;
$this->context = $context ?: new RequestContext();
$this->context = $context ?? new RequestContext();
$this->logger = $logger;
$this->setOptions($options);
if ($parameters) {
$this->paramFetcher = \Closure::fromCallable([$parameters, 'get']);
} elseif ($container instanceof SymfonyContainerInterface) {
$this->paramFetcher = \Closure::fromCallable([$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__));
}
$this->defaultLocale = $defaultLocale;
}
/**
@@ -56,6 +68,16 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
$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));
try {
$containerFile = ($this->paramFetcher)('kernel.cache_dir').'/'.($this->paramFetcher)('kernel.container_class').'.php';
if (file_exists($containerFile)) {
$this->collection->addResource(new FileResource($containerFile));
} else {
$this->collection->addResource(new FileExistenceResource($containerFile));
}
} catch (ParameterNotFoundException $exception) {
}
}
return $this->collection;
@@ -63,8 +85,10 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
/**
* {@inheritdoc}
*
* @return string[] A list of classes to preload on PHP 7.4+
*/
public function warmUp($cacheDir)
public function warmUp(string $cacheDir)
{
$currentDir = $this->getOption('cache_dir');
@@ -74,6 +98,11 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
$this->getGenerator();
$this->setOption('cache_dir', $currentDir);
return [
$this->getOption('generator_class'),
$this->getOption('matcher_class'),
];
}
/**
@@ -101,15 +130,15 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
$schemes = [];
foreach ($route->getSchemes() as $scheme) {
$schemes = array_merge($schemes, explode('|', $this->resolve($scheme)));
$schemes[] = explode('|', $this->resolve($scheme));
}
$route->setSchemes($schemes);
$route->setSchemes(array_merge([], ...$schemes));
$methods = [];
foreach ($route->getMethods() as $method) {
$methods = array_merge($methods, explode('|', $this->resolve($method)));
$methods[] = explode('|', $this->resolve($method));
}
$route->setMethods($methods);
$route->setMethods(array_merge([], ...$methods));
$route->setCondition($this->resolve($route->getCondition()));
}
}
@@ -139,9 +168,7 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
return $value;
}
$container = $this->container;
$escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($container, $value) {
$escapedValue = preg_replace_callback('/%%|%([^%\s]++)%/', function ($match) use ($value) {
// skip %%
if (!isset($match[1])) {
return '%%';
@@ -151,15 +178,21 @@ class Router extends BaseRouter implements WarmableInterface, ServiceSubscriberI
throw new RuntimeException(sprintf('Using "%%%s%%" is not allowed in routing configuration.', $match[1]));
}
$resolved = $container->getParameter($match[1]);
$resolved = ($this->paramFetcher)($match[1]);
if (\is_string($resolved) || is_numeric($resolved)) {
if (is_scalar($resolved)) {
$this->collectedParameters[$match[1]] = $resolved;
return (string) $this->resolve($resolved);
if (\is_string($resolved)) {
$resolved = $this->resolve($resolved);
}
if (is_scalar($resolved)) {
return false === $resolved ? '0' : (string) $resolved;
}
}
throw new RuntimeException(sprintf('The container parameter "%s", used in the route configuration value "%s", must be a string or numeric, but it is of type "%s".', $match[1], $value, \gettype($resolved)));
throw new RuntimeException(sprintf('The container parameter "%s", used in the route configuration value "%s", must be a string or numeric, but it is of type "%s".', $match[1], $value, get_debug_type($resolved)));
}, $value);
return str_replace('%%', '%', $escapedValue);