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:
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
use Symfony\Component\Console\Completion\CompletionSuggestions;
|
||||
@@ -19,28 +20,31 @@ 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\DependencyInjection\ServiceLocator;
|
||||
use Symfony\Component\Workflow\Definition;
|
||||
use Symfony\Component\Workflow\Dumper\GraphvizDumper;
|
||||
use Symfony\Component\Workflow\Dumper\MermaidDumper;
|
||||
use Symfony\Component\Workflow\Dumper\PlantUmlDumper;
|
||||
use Symfony\Component\Workflow\Dumper\StateMachineGraphvizDumper;
|
||||
use Symfony\Component\Workflow\Marking;
|
||||
use Symfony\Component\Workflow\StateMachine;
|
||||
|
||||
/**
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
#[AsCommand(name: 'workflow:dump', description: 'Dump a workflow')]
|
||||
class WorkflowDumpCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'workflow:dump';
|
||||
protected static $defaultDescription = 'Dump a workflow';
|
||||
/**
|
||||
* string is the service id.
|
||||
*
|
||||
* @var array<string, Definition>
|
||||
*/
|
||||
private $workflows = [];
|
||||
private array $definitions = [];
|
||||
|
||||
private ServiceLocator $workflows;
|
||||
|
||||
private const DUMP_FORMAT_OPTIONS = [
|
||||
'puml',
|
||||
@@ -48,26 +52,30 @@ class WorkflowDumpCommand extends Command
|
||||
'dot',
|
||||
];
|
||||
|
||||
public function __construct(array $workflows)
|
||||
public function __construct($workflows)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->workflows = $workflows;
|
||||
if ($workflows instanceof ServiceLocator) {
|
||||
$this->workflows = $workflows;
|
||||
} elseif (\is_array($workflows)) {
|
||||
$this->definitions = $workflows;
|
||||
trigger_deprecation('symfony/framework-bundle', '6.2', 'Passing an array of definitions in "%s()" is deprecated. Inject a ServiceLocator filled with all workflows instead.', __METHOD__);
|
||||
} else {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be an array or a ServiceLocator, "%s" given.', __METHOD__, \gettype($workflows)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setDefinition([
|
||||
new InputArgument('name', InputArgument::REQUIRED, 'A workflow name'),
|
||||
new InputArgument('marking', InputArgument::IS_ARRAY, 'A marking (a list of places)'),
|
||||
new InputOption('label', 'l', InputOption::VALUE_REQUIRED, 'Label a graph'),
|
||||
new InputOption('with-metadata', null, InputOption::VALUE_NONE, 'Include the workflow\'s metadata in the dumped graph', null),
|
||||
new InputOption('dump-format', null, InputOption::VALUE_REQUIRED, 'The dump format ['.implode('|', self::DUMP_FORMAT_OPTIONS).']', 'dot'),
|
||||
])
|
||||
->setDescription(self::$defaultDescription)
|
||||
->setHelp(<<<'EOF'
|
||||
The <info>%command.name%</info> command dumps the graphical representation of a
|
||||
workflow in different formats
|
||||
@@ -80,24 +88,26 @@ EOF
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$workflowName = $input->getArgument('name');
|
||||
|
||||
$workflow = null;
|
||||
|
||||
if (isset($this->workflows['workflow.'.$workflowName])) {
|
||||
$workflow = $this->workflows['workflow.'.$workflowName];
|
||||
if (isset($this->workflows)) {
|
||||
if (!$this->workflows->has($workflowName)) {
|
||||
throw new InvalidArgumentException(sprintf('The workflow named "%s" cannot be found.', $workflowName));
|
||||
}
|
||||
$workflow = $this->workflows->get($workflowName);
|
||||
$type = $workflow instanceof StateMachine ? 'state_machine' : 'workflow';
|
||||
$definition = $workflow->getDefinition();
|
||||
} elseif (isset($this->definitions['workflow.'.$workflowName])) {
|
||||
$definition = $this->definitions['workflow.'.$workflowName];
|
||||
$type = 'workflow';
|
||||
} elseif (isset($this->workflows['state_machine.'.$workflowName])) {
|
||||
$workflow = $this->workflows['state_machine.'.$workflowName];
|
||||
} elseif (isset($this->definitions['state_machine.'.$workflowName])) {
|
||||
$definition = $this->definitions['state_machine.'.$workflowName];
|
||||
$type = 'state_machine';
|
||||
}
|
||||
|
||||
if (null === $workflow) {
|
||||
if (null === $definition) {
|
||||
throw new InvalidArgumentException(sprintf('No service found for "workflow.%1$s" nor "state_machine.%1$s".', $workflowName));
|
||||
}
|
||||
|
||||
@@ -125,12 +135,11 @@ EOF
|
||||
|
||||
$options = [
|
||||
'name' => $workflowName,
|
||||
'with-metadata' => $input->getOption('with-metadata'),
|
||||
'nofooter' => true,
|
||||
'graph' => [
|
||||
'label' => $input->getOption('label'),
|
||||
],
|
||||
'label' => $input->getOption('label'),
|
||||
];
|
||||
$output->writeln($dumper->dump($workflow, $marking, $options));
|
||||
$output->writeln($dumper->dump($definition, $marking, $options));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -138,7 +147,11 @@ EOF
|
||||
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
|
||||
{
|
||||
if ($input->mustSuggestArgumentValuesFor('name')) {
|
||||
$suggestions->suggestValues(array_keys($this->workflows));
|
||||
if (isset($this->workflows)) {
|
||||
$suggestions->suggestValues(array_keys($this->workflows->getProvidedServices()));
|
||||
} else {
|
||||
$suggestions->suggestValues(array_keys($this->definitions));
|
||||
}
|
||||
}
|
||||
|
||||
if ($input->mustSuggestOptionValuesFor('dump-format')) {
|
||||
|
||||
Reference in New Issue
Block a user