mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 19:48:49 +02:00
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:
@@ -11,42 +11,39 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
use Symfony\Component\Console\Completion\CompletionSuggestions;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Contracts\Service\ServiceProviderInterface;
|
||||
|
||||
/**
|
||||
* A console command for retrieving information about event dispatcher.
|
||||
*
|
||||
* @author Matthieu Auger <mail@matthieuauger.com>
|
||||
*
|
||||
* @final since version 3.4
|
||||
* @final
|
||||
*/
|
||||
class EventDispatcherDebugCommand extends ContainerAwareCommand
|
||||
class EventDispatcherDebugCommand extends Command
|
||||
{
|
||||
private const DEFAULT_DISPATCHER = 'event_dispatcher';
|
||||
|
||||
protected static $defaultName = 'debug:event-dispatcher';
|
||||
private $dispatcher;
|
||||
protected static $defaultDescription = 'Display configured listeners for an application';
|
||||
private $dispatchers;
|
||||
|
||||
/**
|
||||
* @param EventDispatcherInterface $dispatcher
|
||||
*/
|
||||
public function __construct($dispatcher = null)
|
||||
public function __construct(ContainerInterface $dispatchers)
|
||||
{
|
||||
if (!$dispatcher instanceof EventDispatcherInterface) {
|
||||
@trigger_error(sprintf('%s() expects an instance of "%s" as first argument since Symfony 3.4. Not passing it is deprecated and will throw a TypeError in 4.0.', __METHOD__, EventDispatcherInterface::class), \E_USER_DEPRECATED);
|
||||
|
||||
parent::__construct($dispatcher);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->dispatchers = $dispatchers;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,11 +53,12 @@ class EventDispatcherDebugCommand extends ContainerAwareCommand
|
||||
{
|
||||
$this
|
||||
->setDefinition([
|
||||
new InputArgument('event', InputArgument::OPTIONAL, 'An event name'),
|
||||
new InputArgument('event', InputArgument::OPTIONAL, 'An event name or a part of the event name'),
|
||||
new InputOption('dispatcher', null, InputOption::VALUE_REQUIRED, 'To view events of a specific event dispatcher', self::DEFAULT_DISPATCHER),
|
||||
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
|
||||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
|
||||
])
|
||||
->setDescription('Displays configured listeners for an application')
|
||||
->setDescription(self::$defaultDescription)
|
||||
->setHelp(<<<'EOF'
|
||||
The <info>%command.name%</info> command displays all configured listeners:
|
||||
|
||||
@@ -79,42 +77,88 @@ EOF
|
||||
*
|
||||
* @throws \LogicException
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
// BC to be removed in 4.0
|
||||
if (null === $this->dispatcher) {
|
||||
$this->dispatcher = $this->getEventDispatcher();
|
||||
}
|
||||
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$options = [];
|
||||
$dispatcherServiceName = $input->getOption('dispatcher');
|
||||
if (!$this->dispatchers->has($dispatcherServiceName)) {
|
||||
$io->getErrorStyle()->error(sprintf('Event dispatcher "%s" is not available.', $dispatcherServiceName));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$dispatcher = $this->dispatchers->get($dispatcherServiceName);
|
||||
|
||||
if ($event = $input->getArgument('event')) {
|
||||
if (!$this->dispatcher->hasListeners($event)) {
|
||||
$io->getErrorStyle()->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
|
||||
if ($dispatcher->hasListeners($event)) {
|
||||
$options = ['event' => $event];
|
||||
} else {
|
||||
// if there is no direct match, try find partial matches
|
||||
$events = $this->searchForEvent($dispatcher, $event);
|
||||
if (0 === \count($events)) {
|
||||
$io->getErrorStyle()->warning(sprintf('The event "%s" does not have any registered listeners.', $event));
|
||||
|
||||
return;
|
||||
return 0;
|
||||
} elseif (1 === \count($events)) {
|
||||
$options = ['event' => $events[array_key_first($events)]];
|
||||
} else {
|
||||
$options = ['events' => $events];
|
||||
}
|
||||
}
|
||||
|
||||
$options = ['event' => $event];
|
||||
}
|
||||
|
||||
$helper = new DescriptorHelper();
|
||||
|
||||
if (self::DEFAULT_DISPATCHER !== $dispatcherServiceName) {
|
||||
$options['dispatcher_service_name'] = $dispatcherServiceName;
|
||||
}
|
||||
|
||||
$options['format'] = $input->getOption('format');
|
||||
$options['raw_text'] = $input->getOption('raw');
|
||||
$options['output'] = $io;
|
||||
$helper->describe($io, $this->dispatcher, $options);
|
||||
$helper->describe($io, $dispatcher, $options);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the Event Dispatcher from the container.
|
||||
*
|
||||
* BC to removed in 4.0
|
||||
*
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getEventDispatcher()
|
||||
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
|
||||
{
|
||||
return $this->getContainer()->get('event_dispatcher');
|
||||
if ($input->mustSuggestArgumentValuesFor('event')) {
|
||||
$dispatcherServiceName = $input->getOption('dispatcher');
|
||||
if ($this->dispatchers->has($dispatcherServiceName)) {
|
||||
$dispatcher = $this->dispatchers->get($dispatcherServiceName);
|
||||
$suggestions->suggestValues(array_keys($dispatcher->getListeners()));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($input->mustSuggestOptionValuesFor('dispatcher')) {
|
||||
if ($this->dispatchers instanceof ServiceProviderInterface) {
|
||||
$suggestions->suggestValues(array_keys($this->dispatchers->getProvidedServices()));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($input->mustSuggestOptionValuesFor('format')) {
|
||||
$suggestions->suggestValues((new DescriptorHelper())->getFormats());
|
||||
}
|
||||
}
|
||||
|
||||
private function searchForEvent(EventDispatcherInterface $dispatcher, string $needle): array
|
||||
{
|
||||
$output = [];
|
||||
$lcNeedle = strtolower($needle);
|
||||
$allEvents = array_keys($dispatcher->getListeners());
|
||||
foreach ($allEvents as $event) {
|
||||
if (str_contains(strtolower($event), $lcNeedle)) {
|
||||
$output[] = $event;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user