mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user