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

@@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Helper\Dumper;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Argument\AbstractArgument;
@@ -25,8 +26,8 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ErrorHandler\ErrorRenderer\FileLinkFormatter;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
@@ -37,14 +38,14 @@ use Symfony\Component\Routing\RouteCollection;
*/
class TextDescriptor extends Descriptor
{
private $fileLinkFormatter;
private ?FileLinkFormatter $fileLinkFormatter;
public function __construct(FileLinkFormatter $fileLinkFormatter = null)
{
$this->fileLinkFormatter = $fileLinkFormatter;
}
protected function describeRouteCollection(RouteCollection $routes, array $options = [])
protected function describeRouteCollection(RouteCollection $routes, array $options = []): void
{
$showControllers = isset($options['show_controllers']) && $options['show_controllers'];
@@ -53,6 +54,10 @@ class TextDescriptor extends Descriptor
$tableHeaders[] = 'Controller';
}
if ($showAliases = $options['show_aliases'] ?? false) {
$tableHeaders[] = 'Aliases';
}
$tableRows = [];
foreach ($routes->all() as $name => $route) {
$controller = $route->getDefault('_controller');
@@ -69,6 +74,10 @@ class TextDescriptor extends Descriptor
$row[] = $controller ? $this->formatControllerLink($controller, $this->formatCallable($controller), $options['container'] ?? null) : '';
}
if ($showAliases) {
$row[] = implode('|', ($reverseAliases ??= $this->getReverseAliases($routes))[$name] ?? []);
}
$tableRows[] = $row;
}
@@ -81,7 +90,7 @@ class TextDescriptor extends Descriptor
}
}
protected function describeRoute(Route $route, array $options = [])
protected function describeRoute(Route $route, array $options = []): void
{
$defaults = $route->getDefaults();
if (isset($defaults['_controller'])) {
@@ -98,7 +107,7 @@ class TextDescriptor extends Descriptor
['Scheme', $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'],
['Method', $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'],
['Requirements', $route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM'],
['Class', \get_class($route)],
['Class', $route::class],
['Defaults', $this->formatRouterConfig($defaults)],
['Options', $this->formatRouterConfig($route->getOptions())],
];
@@ -112,20 +121,29 @@ class TextDescriptor extends Descriptor
$table->render();
}
protected function describeContainerParameters(ParameterBag $parameters, array $options = [])
protected function describeContainerParameters(ParameterBag $parameters, array $options = []): void
{
$tableHeaders = ['Parameter', 'Value'];
$deprecatedParameters = $parameters->allDeprecated();
$tableRows = [];
foreach ($this->sortParameters($parameters) as $parameter => $value) {
$tableRows[] = [$parameter, $this->formatParameter($value)];
if (isset($deprecatedParameters[$parameter])) {
$tableRows[] = [new TableCell(
sprintf('<comment>(Since %s %s: %s)</comment>', $deprecatedParameters[$parameter][0], $deprecatedParameters[$parameter][1], sprintf(...\array_slice($deprecatedParameters[$parameter], 2))),
['colspan' => 2]
)];
}
}
$options['output']->title('Symfony Container Parameters');
$options['output']->table($tableHeaders, $tableRows);
}
protected function describeContainerTags(ContainerBuilder $builder, array $options = [])
protected function describeContainerTags(ContainerBuilder $container, array $options = []): void
{
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
@@ -135,34 +153,34 @@ class TextDescriptor extends Descriptor
$options['output']->title('Symfony Container Tags');
}
foreach ($this->findDefinitionsByTag($builder, $showHidden) as $tag => $definitions) {
foreach ($this->findDefinitionsByTag($container, $showHidden) as $tag => $definitions) {
$options['output']->section(sprintf('"%s" tag', $tag));
$options['output']->listing(array_keys($definitions));
}
}
protected function describeContainerService(object $service, array $options = [], ContainerBuilder $builder = null)
protected function describeContainerService(object $service, array $options = [], ContainerBuilder $container = null): void
{
if (!isset($options['id'])) {
throw new \InvalidArgumentException('An "id" option must be provided.');
}
if ($service instanceof Alias) {
$this->describeContainerAlias($service, $options, $builder);
$this->describeContainerAlias($service, $options, $container);
} elseif ($service instanceof Definition) {
$this->describeContainerDefinition($service, $options);
$this->describeContainerDefinition($service, $options, $container);
} else {
$options['output']->title(sprintf('Information for Service "<info>%s</info>"', $options['id']));
$options['output']->table(
['Service ID', 'Class'],
[
[$options['id'] ?? '-', \get_class($service)],
[$options['id'] ?? '-', $service::class],
]
);
}
}
protected function describeContainerServices(ContainerBuilder $builder, array $options = [])
protected function describeContainerServices(ContainerBuilder $container, array $options = []): void
{
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
$showTag = $options['tag'] ?? null;
@@ -180,8 +198,8 @@ class TextDescriptor extends Descriptor
$options['output']->title($title);
$serviceIds = isset($options['tag']) && $options['tag']
? $this->sortTaggedServicesByPriority($builder->findTaggedServiceIds($options['tag']))
: $this->sortServiceIds($builder->getServiceIds());
? $this->sortTaggedServicesByPriority($container->findTaggedServiceIds($options['tag']))
: $this->sortServiceIds($container->getServiceIds());
$maxTags = [];
if (isset($options['filter'])) {
@@ -189,7 +207,7 @@ class TextDescriptor extends Descriptor
}
foreach ($serviceIds as $key => $serviceId) {
$definition = $this->resolveServiceDefinition($builder, $serviceId);
$definition = $this->resolveServiceDefinition($container, $serviceId);
// filter out hidden services unless shown explicitly
if ($showHidden xor '.' === ($serviceId[0] ?? null)) {
@@ -198,6 +216,10 @@ class TextDescriptor extends Descriptor
}
if ($definition instanceof Definition) {
if ($definition->hasTag('container.excluded')) {
unset($serviceIds[$key]);
continue;
}
if ($showTag) {
$tags = $definition->getTag($showTag);
foreach ($tags as $tag) {
@@ -205,6 +227,10 @@ class TextDescriptor extends Descriptor
if (!isset($maxTags[$key])) {
$maxTags[$key] = \strlen($key);
}
if (\is_array($value)) {
$value = $this->formatParameter($value);
}
if (\strlen($value) > $maxTags[$key]) {
$maxTags[$key] = \strlen($value);
}
@@ -221,7 +247,7 @@ class TextDescriptor extends Descriptor
$tableRows = [];
$rawOutput = isset($options['raw_text']) && $options['raw_text'];
foreach ($serviceIds as $serviceId) {
$definition = $this->resolveServiceDefinition($builder, $serviceId);
$definition = $this->resolveServiceDefinition($container, $serviceId);
$styledServiceId = $rawOutput ? $serviceId : sprintf('<fg=cyan>%s</fg=cyan>', OutputFormatter::escape($serviceId));
if ($definition instanceof Definition) {
@@ -229,7 +255,11 @@ class TextDescriptor extends Descriptor
foreach ($this->sortByPriority($definition->getTag($showTag)) as $key => $tag) {
$tagValues = [];
foreach ($tagsNames as $tagName) {
$tagValues[] = $tag[$tagName] ?? '';
if (\is_array($tagValue = $tag[$tagName] ?? '')) {
$tagValue = $this->formatParameter($tagValue);
}
$tagValues[] = $tagValue;
}
if (0 === $key) {
$tableRows[] = array_merge([$serviceId], $tagValues, [$definition->getClass()]);
@@ -244,14 +274,14 @@ class TextDescriptor extends Descriptor
$alias = $definition;
$tableRows[] = array_merge([$styledServiceId, sprintf('alias for "%s"', $alias)], $tagsCount ? array_fill(0, $tagsCount, '') : []);
} else {
$tableRows[] = array_merge([$styledServiceId, \get_class($definition)], $tagsCount ? array_fill(0, $tagsCount, '') : []);
$tableRows[] = array_merge([$styledServiceId, $definition::class], $tagsCount ? array_fill(0, $tagsCount, '') : []);
}
}
$options['output']->table($tableHeaders, $tableRows);
}
protected function describeContainerDefinition(Definition $definition, array $options = [])
protected function describeContainerDefinition(Definition $definition, array $options = [], ContainerBuilder $container = null): void
{
if (isset($options['id'])) {
$options['output']->title(sprintf('Information for Service "<info>%s</info>"', $options['id']));
@@ -271,9 +301,7 @@ class TextDescriptor extends Descriptor
$tagInformation = [];
foreach ($tags as $tagName => $tagData) {
foreach ($tagData as $tagParameters) {
$parameters = array_map(function ($key, $value) {
return sprintf('<info>%s</info>: %s', $key, $value);
}, array_keys($tagParameters), array_values($tagParameters));
$parameters = array_map(fn ($key, $value) => sprintf('<info>%s</info>: %s', $key, \is_array($value) ? $this->formatParameter($value) : $value), array_keys($tagParameters), array_values($tagParameters));
$parameters = implode(', ', $parameters);
if ('' === $parameters) {
@@ -360,12 +388,15 @@ class TextDescriptor extends Descriptor
$tableRows[] = ['Arguments', implode("\n", $argumentsInformation)];
}
$inEdges = null !== $container && isset($options['id']) ? $this->getServiceEdges($container, $options['id']) : [];
$tableRows[] = ['Usages', $inEdges ? implode(\PHP_EOL, $inEdges) : 'none'];
$options['output']->table($tableHeaders, $tableRows);
}
protected function describeContainerDeprecations(ContainerBuilder $builder, array $options = []): void
protected function describeContainerDeprecations(ContainerBuilder $container, array $options = []): void
{
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $builder->getParameter('kernel.build_dir'), $builder->getParameter('kernel.container_class'));
$containerDeprecationFilePath = sprintf('%s/%sDeprecations.log', $container->getParameter('kernel.build_dir'), $container->getParameter('kernel.container_class'));
if (!file_exists($containerDeprecationFilePath)) {
$options['output']->warning('The deprecation file does not exist, please try warming the cache first.');
@@ -389,7 +420,7 @@ class TextDescriptor extends Descriptor
$options['output']->listing($formattedLogs);
}
protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $builder = null)
protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $container = null): void
{
if ($alias->isPublic() && !$alias->isPrivate()) {
$options['output']->comment(sprintf('This service is a <info>public</info> alias for the service <info>%s</info>', (string) $alias));
@@ -397,24 +428,31 @@ class TextDescriptor extends Descriptor
$options['output']->comment(sprintf('This service is a <comment>private</comment> alias for the service <info>%s</info>', (string) $alias));
}
if (!$builder) {
if (!$container) {
return;
}
$this->describeContainerDefinition($builder->getDefinition((string) $alias), array_merge($options, ['id' => (string) $alias]));
$this->describeContainerDefinition($container->getDefinition((string) $alias), array_merge($options, ['id' => (string) $alias]), $container);
}
protected function describeContainerParameter($parameter, array $options = [])
protected function describeContainerParameter(mixed $parameter, ?array $deprecation, array $options = []): void
{
$options['output']->table(
['Parameter', 'Value'],
[
[$options['parameter'], $this->formatParameter($parameter),
],
]);
$parameterName = $options['parameter'];
$rows = [
[$parameterName, $this->formatParameter($parameter)],
];
if ($deprecation) {
$rows[] = [new TableCell(
sprintf('<comment>(Since %s %s: %s)</comment>', $deprecation[0], $deprecation[1], sprintf(...\array_slice($deprecation, 2))),
['colspan' => 2]
)];
}
$options['output']->table(['Parameter', 'Value'], $rows);
}
protected function describeContainerEnvVars(array $envs, array $options = [])
protected function describeContainerEnvVars(array $envs, array $options = []): void
{
$dump = new Dumper($this->output);
$options['output']->title('Symfony Container Environment Variables');
@@ -476,7 +514,7 @@ class TextDescriptor extends Descriptor
}
}
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = [])
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = []): void
{
$event = $options['event'] ?? null;
$dispatcherServiceName = $options['dispatcher_service_name'] ?? null;
@@ -493,7 +531,7 @@ class TextDescriptor extends Descriptor
} else {
$title .= ' Grouped by Event';
// Try to see if "events" exists
$registeredListeners = \array_key_exists('events', $options) ? array_combine($options['events'], array_map(function ($event) use ($eventDispatcher) { return $eventDispatcher->getListeners($event); }, $options['events'])) : $eventDispatcher->getListeners();
$registeredListeners = \array_key_exists('events', $options) ? array_combine($options['events'], array_map(fn ($event) => $eventDispatcher->getListeners($event), $options['events'])) : $eventDispatcher->getListeners();
}
$options['output']->title($title);
@@ -508,12 +546,12 @@ class TextDescriptor extends Descriptor
}
}
protected function describeCallable($callable, array $options = [])
protected function describeCallable(mixed $callable, array $options = []): void
{
$this->writeText($this->formatCallable($callable), $options);
}
private function renderEventListenerTable(EventDispatcherInterface $eventDispatcher, string $event, array $eventListeners, SymfonyStyle $io)
private function renderEventListenerTable(EventDispatcherInterface $eventDispatcher, string $event, array $eventListeners, SymfonyStyle $io): void
{
$tableHeaders = ['Order', 'Callable', 'Priority'];
$tableRows = [];
@@ -527,7 +565,7 @@ class TextDescriptor extends Descriptor
private function formatRouterConfig(array $config): string
{
if (empty($config)) {
if (!$config) {
return 'NONE';
}
@@ -541,7 +579,7 @@ class TextDescriptor extends Descriptor
return trim($configAsString);
}
private function formatControllerLink($controller, string $anchorText, callable $getContainer = null): string
private function formatControllerLink(mixed $controller, string $anchorText, callable $getContainer = null): string
{
if (null === $this->fileLinkFormatter) {
return $anchorText;
@@ -563,7 +601,7 @@ class TextDescriptor extends Descriptor
} else {
$r = new \ReflectionFunction($controller);
}
} catch (\ReflectionException $e) {
} catch (\ReflectionException) {
if (\is_array($controller)) {
$controller = implode('::', $controller);
}
@@ -582,7 +620,7 @@ class TextDescriptor extends Descriptor
try {
$r = new \ReflectionMethod($container->findDefinition($id)->getClass(), $method);
} catch (\ReflectionException $e) {
} catch (\ReflectionException) {
return $anchorText;
}
}
@@ -595,11 +633,11 @@ class TextDescriptor extends Descriptor
return $anchorText;
}
private function formatCallable($callable): string
private function formatCallable(mixed $callable): string
{
if (\is_array($callable)) {
if (\is_object($callable[0])) {
return sprintf('%s::%s()', \get_class($callable[0]), $callable[1]);
return sprintf('%s::%s()', $callable[0]::class, $callable[1]);
}
return sprintf('%s::%s()', $callable[0], $callable[1]);
@@ -622,13 +660,13 @@ class TextDescriptor extends Descriptor
}
if (method_exists($callable, '__invoke')) {
return sprintf('%s::__invoke()', \get_class($callable));
return sprintf('%s::__invoke()', $callable::class);
}
throw new \InvalidArgumentException('Callable is not describable.');
}
private function writeText(string $content, array $options = [])
private function writeText(string $content, array $options = []): void
{
$this->write(
isset($options['raw_text']) && $options['raw_text'] ? strip_tags($content) : $content,