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

@@ -29,7 +29,7 @@ use Symfony\Component\Routing\RouteCollection;
*/
class MarkdownDescriptor extends Descriptor
{
protected function describeRouteCollection(RouteCollection $routes, array $options = [])
protected function describeRouteCollection(RouteCollection $routes, array $options = []): void
{
$first = true;
foreach ($routes->all() as $name => $route) {
@@ -39,11 +39,14 @@ class MarkdownDescriptor extends Descriptor
$this->write("\n\n");
}
$this->describeRoute($route, ['name' => $name]);
if (($showAliases ??= $options['show_aliases'] ?? false) && $aliases = ($reverseAliases ??= $this->getReverseAliases($routes))[$name] ?? []) {
$this->write(sprintf("- Aliases: \n%s", implode("\n", array_map(static fn (string $alias): string => sprintf(' - %s', $alias), $aliases))));
}
}
$this->write("\n");
}
protected function describeRoute(Route $route, array $options = [])
protected function describeRoute(Route $route, array $options = []): void
{
$output = '- Path: '.$route->getPath()
."\n".'- Path Regex: '.$route->compile()->getRegex()
@@ -51,7 +54,7 @@ class MarkdownDescriptor extends Descriptor
."\n".'- Host Regex: '.('' !== $route->getHost() ? $route->compile()->getHostRegex() : '')
."\n".'- Scheme: '.($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY')
."\n".'- Method: '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY')
."\n".'- Class: '.\get_class($route)
."\n".'- Class: '.$route::class
."\n".'- Defaults: '.$this->formatRouterConfig($route->getDefaults())
."\n".'- Requirements: '.($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM')
."\n".'- Options: '.$this->formatRouterConfig($route->getOptions());
@@ -66,29 +69,36 @@ class MarkdownDescriptor extends Descriptor
$this->write("\n");
}
protected function describeContainerParameters(ParameterBag $parameters, array $options = [])
protected function describeContainerParameters(ParameterBag $parameters, array $options = []): void
{
$deprecatedParameters = $parameters->allDeprecated();
$this->write("Container parameters\n====================\n");
foreach ($this->sortParameters($parameters) as $key => $value) {
$this->write(sprintf("\n- `%s`: `%s`", $key, $this->formatParameter($value)));
$this->write(sprintf(
"\n- `%s`: `%s`%s",
$key,
$this->formatParameter($value),
isset($deprecatedParameters[$key]) ? sprintf(' *Since %s %s: %s*', $deprecatedParameters[$key][0], $deprecatedParameters[$key][1], sprintf(...\array_slice($deprecatedParameters[$key], 2))) : ''
));
}
}
protected function describeContainerTags(ContainerBuilder $builder, array $options = [])
protected function describeContainerTags(ContainerBuilder $container, array $options = []): void
{
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
$this->write("Container tags\n==============");
foreach ($this->findDefinitionsByTag($builder, $showHidden) as $tag => $definitions) {
foreach ($this->findDefinitionsByTag($container, $showHidden) as $tag => $definitions) {
$this->write("\n\n".$tag."\n".str_repeat('-', \strlen($tag)));
foreach ($definitions as $serviceId => $definition) {
$this->write("\n\n");
$this->describeContainerDefinition($definition, ['omit_tags' => true, 'id' => $serviceId]);
$this->describeContainerDefinition($definition, ['omit_tags' => true, 'id' => $serviceId], $container);
}
}
}
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.');
@@ -97,17 +107,17 @@ class MarkdownDescriptor extends Descriptor
$childOptions = array_merge($options, ['id' => $options['id'], 'as_array' => true]);
if ($service instanceof Alias) {
$this->describeContainerAlias($service, $childOptions, $builder);
$this->describeContainerAlias($service, $childOptions, $container);
} elseif ($service instanceof Definition) {
$this->describeContainerDefinition($service, $childOptions);
$this->describeContainerDefinition($service, $childOptions, $container);
} else {
$this->write(sprintf('**`%s`:** `%s`', $options['id'], \get_class($service)));
$this->write(sprintf('**`%s`:** `%s`', $options['id'], $service::class));
}
}
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)) {
throw new RuntimeException('The deprecation file does not exist, please try warming the cache first.');
}
@@ -132,7 +142,7 @@ class MarkdownDescriptor extends Descriptor
}
}
protected function describeContainerServices(ContainerBuilder $builder, array $options = [])
protected function describeContainerServices(ContainerBuilder $container, array $options = []): void
{
$showHidden = isset($options['show_hidden']) && $options['show_hidden'];
@@ -143,8 +153,8 @@ class MarkdownDescriptor extends Descriptor
$this->write($title."\n".str_repeat('=', \strlen($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());
$showArguments = isset($options['show_arguments']) && $options['show_arguments'];
$services = ['definitions' => [], 'aliases' => [], 'services' => []];
@@ -153,7 +163,7 @@ class MarkdownDescriptor extends Descriptor
}
foreach ($serviceIds as $serviceId) {
$service = $this->resolveServiceDefinition($builder, $serviceId);
$service = $this->resolveServiceDefinition($container, $serviceId);
if ($showHidden xor '.' === ($serviceId[0] ?? null)) {
continue;
@@ -162,6 +172,9 @@ class MarkdownDescriptor extends Descriptor
if ($service instanceof Alias) {
$services['aliases'][$serviceId] = $service;
} elseif ($service instanceof Definition) {
if ($service->hasTag('container.excluded')) {
continue;
}
$services['definitions'][$serviceId] = $service;
} else {
$services['services'][$serviceId] = $service;
@@ -172,7 +185,7 @@ class MarkdownDescriptor extends Descriptor
$this->write("\n\nDefinitions\n-----------\n");
foreach ($services['definitions'] as $id => $service) {
$this->write("\n");
$this->describeContainerDefinition($service, ['id' => $id, 'show_arguments' => $showArguments]);
$this->describeContainerDefinition($service, ['id' => $id, 'show_arguments' => $showArguments], $container);
}
}
@@ -188,12 +201,12 @@ class MarkdownDescriptor extends Descriptor
$this->write("\n\nServices\n--------\n");
foreach ($services['services'] as $id => $service) {
$this->write("\n");
$this->write(sprintf('- `%s`: `%s`', $id, \get_class($service)));
$this->write(sprintf('- `%s`: `%s`', $id, $service::class));
}
}
}
protected function describeContainerDefinition(Definition $definition, array $options = [])
protected function describeContainerDefinition(Definition $definition, array $options = [], ContainerBuilder $container = null): void
{
$output = '';
@@ -211,6 +224,13 @@ class MarkdownDescriptor extends Descriptor
."\n".'- Autoconfigured: '.($definition->isAutoconfigured() ? 'yes' : 'no')
;
if ($definition->isDeprecated()) {
$output .= "\n".'- Deprecated: yes';
$output .= "\n".'- Deprecation message: '.$definition->getDeprecation($options['id'])['message'];
} else {
$output .= "\n".'- Deprecated: no';
}
if (isset($options['show_arguments']) && $options['show_arguments']) {
$output .= "\n".'- Arguments: '.($definition->getArguments() ? 'yes' : 'no');
}
@@ -244,16 +264,19 @@ class MarkdownDescriptor extends Descriptor
foreach ($tagData as $parameters) {
$output .= "\n".'- Tag: `'.$tagName.'`';
foreach ($parameters as $name => $value) {
$output .= "\n".' - '.ucfirst($name).': '.$value;
$output .= "\n".' - '.ucfirst($name).': '.(\is_array($value) ? $this->formatParameter($value) : $value);
}
}
}
}
$inEdges = null !== $container && isset($options['id']) ? $this->getServiceEdges($container, $options['id']) : [];
$output .= "\n".'- Usages: '.($inEdges ? implode(', ', $inEdges) : 'none');
$this->write(isset($options['id']) ? sprintf("### %s\n\n%s\n", $options['id'], $output) : $output);
}
protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $builder = null)
protected function describeContainerAlias(Alias $alias, array $options = [], ContainerBuilder $container = null): void
{
$output = '- Service: `'.$alias.'`'
."\n".'- Public: '.($alias->isPublic() && !$alias->isPrivate() ? 'yes' : 'no');
@@ -266,25 +289,29 @@ class MarkdownDescriptor extends Descriptor
$this->write(sprintf("### %s\n\n%s\n", $options['id'], $output));
if (!$builder) {
if (!$container) {
return;
}
$this->write("\n");
$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
{
$this->write(isset($options['parameter']) ? sprintf("%s\n%s\n\n%s", $options['parameter'], str_repeat('=', \strlen($options['parameter'])), $this->formatParameter($parameter)) : $parameter);
if (isset($options['parameter'])) {
$this->write(sprintf("%s\n%s\n\n%s%s", $options['parameter'], str_repeat('=', \strlen($options['parameter'])), $this->formatParameter($parameter), $deprecation ? sprintf("\n\n*Since %s %s: %s*", $deprecation[0], $deprecation[1], sprintf(...\array_slice($deprecation, 2))) : ''));
} else {
$this->write($parameter);
}
}
protected function describeContainerEnvVars(array $envs, array $options = [])
protected function describeContainerEnvVars(array $envs, array $options = []): void
{
throw new LogicException('Using the markdown format to debug environment variables is not supported.');
}
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;
@@ -300,7 +327,7 @@ class MarkdownDescriptor extends Descriptor
$registeredListeners = $eventDispatcher->getListeners($event);
} else {
// 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();
}
$this->write(sprintf('# %s', $title)."\n");
@@ -326,7 +353,7 @@ class MarkdownDescriptor extends Descriptor
}
}
protected function describeCallable($callable, array $options = [])
protected function describeCallable(mixed $callable, array $options = []): void
{
$string = '';
@@ -335,7 +362,7 @@ class MarkdownDescriptor extends Descriptor
if (\is_object($callable[0])) {
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
$string .= "\n".sprintf('- Class: `%s`', \get_class($callable[0]));
$string .= "\n".sprintf('- Class: `%s`', $callable[0]::class);
} else {
if (!str_starts_with($callable[1], 'parent::')) {
$string .= "\n".sprintf('- Name: `%s`', $callable[1]);
@@ -349,7 +376,9 @@ class MarkdownDescriptor extends Descriptor
}
}
return $this->write($string."\n");
$this->write($string."\n");
return;
}
if (\is_string($callable)) {
@@ -365,7 +394,9 @@ class MarkdownDescriptor extends Descriptor
$string .= "\n- Static: yes";
}
return $this->write($string."\n");
$this->write($string."\n");
return;
}
if ($callable instanceof \Closure) {
@@ -373,7 +404,9 @@ class MarkdownDescriptor extends Descriptor
$r = new \ReflectionFunction($callable);
if (str_contains($r->name, '{closure}')) {
return $this->write($string."\n");
$this->write($string."\n");
return;
}
$string .= "\n".sprintf('- Name: `%s`', $r->name);
@@ -384,14 +417,18 @@ class MarkdownDescriptor extends Descriptor
}
}
return $this->write($string."\n");
$this->write($string."\n");
return;
}
if (method_exists($callable, '__invoke')) {
$string .= "\n- Type: `object`";
$string .= "\n".sprintf('- Name: `%s`', \get_class($callable));
$string .= "\n".sprintf('- Name: `%s`', $callable::class);
return $this->write($string."\n");
$this->write($string."\n");
return;
}
throw new \InvalidArgumentException('Callable is not describable.');