mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 17:18:51 +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:
@@ -12,6 +12,7 @@
|
||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
use Symfony\Component\Console\Completion\CompletionSuggestions;
|
||||
@@ -32,17 +33,12 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#[AsCommand(name: 'debug:container', description: 'Display current services for an application')]
|
||||
class ContainerDebugCommand extends Command
|
||||
{
|
||||
use BuildDebugContainerTrait;
|
||||
|
||||
protected static $defaultName = 'debug:container';
|
||||
protected static $defaultDescription = 'Display current services for an application';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setDefinition([
|
||||
@@ -56,11 +52,10 @@ class ContainerDebugCommand extends Command
|
||||
new InputOption('types', null, InputOption::VALUE_NONE, 'Display types (classes/interfaces) available in the container'),
|
||||
new InputOption('env-var', null, InputOption::VALUE_REQUIRED, 'Display a specific environment variable used in the container'),
|
||||
new InputOption('env-vars', null, InputOption::VALUE_NONE, 'Display environment variables used in the container'),
|
||||
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
|
||||
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
|
||||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
|
||||
new InputOption('deprecations', null, InputOption::VALUE_NONE, 'Display deprecations generated when compiling and warming up the container'),
|
||||
])
|
||||
->setDescription(self::$defaultDescription)
|
||||
->setHelp(<<<'EOF'
|
||||
The <info>%command.name%</info> command displays all configured <comment>public</comment> services:
|
||||
|
||||
@@ -116,9 +111,6 @@ EOF
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
@@ -134,19 +126,26 @@ EOF
|
||||
$options = ['env-vars' => true, 'name' => $envVar];
|
||||
} elseif ($input->getOption('types')) {
|
||||
$options = [];
|
||||
$options['filter'] = [$this, 'filterToServiceTypes'];
|
||||
$options['filter'] = $this->filterToServiceTypes(...);
|
||||
} elseif ($input->getOption('parameters')) {
|
||||
$parameters = [];
|
||||
foreach ($object->getParameterBag()->all() as $k => $v) {
|
||||
$parameterBag = $object->getParameterBag();
|
||||
foreach ($parameterBag->all() as $k => $v) {
|
||||
$parameters[$k] = $object->resolveEnvPlaceholders($v);
|
||||
}
|
||||
$object = new ParameterBag($parameters);
|
||||
if ($parameterBag instanceof ParameterBag) {
|
||||
foreach ($parameterBag->allDeprecated() as $k => $deprecation) {
|
||||
$object->deprecate($k, ...$deprecation);
|
||||
}
|
||||
}
|
||||
$options = [];
|
||||
} elseif ($parameter = $input->getOption('parameter')) {
|
||||
$options = ['parameter' => $parameter];
|
||||
} elseif ($input->getOption('tags')) {
|
||||
$options = ['group_by' => 'tags'];
|
||||
} elseif ($tag = $input->getOption('tag')) {
|
||||
$tag = $this->findProperTagName($input, $errorIo, $object, $tag);
|
||||
$options = ['tag' => $tag];
|
||||
} elseif ($name = $input->getArgument('name')) {
|
||||
$name = $this->findProperServiceName($input, $errorIo, $object, $name, $input->getOption('show-hidden'));
|
||||
@@ -168,6 +167,21 @@ EOF
|
||||
try {
|
||||
$helper->describe($io, $object, $options);
|
||||
|
||||
if ('txt' === $options['format'] && isset($options['id'])) {
|
||||
if ($object->hasDefinition($options['id'])) {
|
||||
$definition = $object->getDefinition($options['id']);
|
||||
if ($definition->isDeprecated()) {
|
||||
$errorIo->warning($definition->getDeprecation($options['id'])['message'] ?? sprintf('The "%s" service is deprecated.', $options['id']));
|
||||
}
|
||||
}
|
||||
if ($object->hasAlias($options['id'])) {
|
||||
$alias = $object->getAlias($options['id']);
|
||||
if ($alias->isDeprecated()) {
|
||||
$errorIo->warning($alias->getDeprecation($options['id'])['message'] ?? sprintf('The "%s" alias is deprecated.', $options['id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['id']) && isset($kernel->getContainer()->getRemovedIds()[$options['id']])) {
|
||||
$errorIo->note(sprintf('The "%s" service or alias has been removed or inlined when the container was compiled.', $options['id']));
|
||||
}
|
||||
@@ -195,8 +209,7 @@ EOF
|
||||
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
|
||||
{
|
||||
if ($input->mustSuggestOptionValuesFor('format')) {
|
||||
$helper = new DescriptorHelper();
|
||||
$suggestions->suggestValues($helper->getFormats());
|
||||
$suggestions->suggestValues($this->getAvailableFormatOptions());
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -235,7 +248,7 @@ EOF
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function validateInput(InputInterface $input)
|
||||
protected function validateInput(InputInterface $input): void
|
||||
{
|
||||
$options = ['tags', 'tag', 'parameters', 'parameter'];
|
||||
|
||||
@@ -254,16 +267,16 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, string $name, bool $showHidden): string
|
||||
private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $container, string $name, bool $showHidden): string
|
||||
{
|
||||
$name = ltrim($name, '\\');
|
||||
|
||||
if ($builder->has($name) || !$input->isInteractive()) {
|
||||
if ($container->has($name) || !$input->isInteractive()) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
$matchingServices = $this->findServiceIdsContaining($builder, $name, $showHidden);
|
||||
if (empty($matchingServices)) {
|
||||
$matchingServices = $this->findServiceIdsContaining($container, $name, $showHidden);
|
||||
if (!$matchingServices) {
|
||||
throw new InvalidArgumentException(sprintf('No services found that match "%s".', $name));
|
||||
}
|
||||
|
||||
@@ -274,14 +287,35 @@ EOF
|
||||
return $io->choice('Select one of the following services to display its information', $matchingServices);
|
||||
}
|
||||
|
||||
private function findServiceIdsContaining(ContainerBuilder $builder, string $name, bool $showHidden): array
|
||||
private function findProperTagName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $container, string $tagName): string
|
||||
{
|
||||
$serviceIds = $builder->getServiceIds();
|
||||
if (\in_array($tagName, $container->findTags(), true) || !$input->isInteractive()) {
|
||||
return $tagName;
|
||||
}
|
||||
|
||||
$matchingTags = $this->findTagsContaining($container, $tagName);
|
||||
if (!$matchingTags) {
|
||||
throw new InvalidArgumentException(sprintf('No tags found that match "%s".', $tagName));
|
||||
}
|
||||
|
||||
if (1 === \count($matchingTags)) {
|
||||
return $matchingTags[0];
|
||||
}
|
||||
|
||||
return $io->choice('Select one of the following tags to display its information', $matchingTags);
|
||||
}
|
||||
|
||||
private function findServiceIdsContaining(ContainerBuilder $container, string $name, bool $showHidden): array
|
||||
{
|
||||
$serviceIds = $container->getServiceIds();
|
||||
$foundServiceIds = $foundServiceIdsIgnoringBackslashes = [];
|
||||
foreach ($serviceIds as $serviceId) {
|
||||
if (!$showHidden && str_starts_with($serviceId, '.')) {
|
||||
continue;
|
||||
}
|
||||
if (!$showHidden && $container->hasDefinition($serviceId) && $container->getDefinition($serviceId)->hasTag('container.excluded')) {
|
||||
continue;
|
||||
}
|
||||
if (false !== stripos(str_replace('\\', '', $serviceId), $name)) {
|
||||
$foundServiceIdsIgnoringBackslashes[] = $serviceId;
|
||||
}
|
||||
@@ -293,6 +327,19 @@ EOF
|
||||
return $foundServiceIds ?: $foundServiceIdsIgnoringBackslashes;
|
||||
}
|
||||
|
||||
private function findTagsContaining(ContainerBuilder $container, string $tagName): array
|
||||
{
|
||||
$tags = $container->findTags();
|
||||
$foundTags = [];
|
||||
foreach ($tags as $tag) {
|
||||
if (str_contains($tag, $tagName)) {
|
||||
$foundTags[] = $tag;
|
||||
}
|
||||
}
|
||||
|
||||
return $foundTags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@@ -310,4 +357,9 @@ EOF
|
||||
|
||||
return class_exists($serviceId) || interface_exists($serviceId, false);
|
||||
}
|
||||
|
||||
private function getAvailableFormatOptions(): array
|
||||
{
|
||||
return (new DescriptorHelper())->getFormats();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user