Skip to content

Commit d2cb5a1

Browse files
committed
[Workflow] Move the dump command to the component
1 parent fd841c3 commit d2cb5a1

File tree

6 files changed

+139
-119
lines changed

6 files changed

+139
-119
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
# Workflow
5656
/src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php @lyrixx
5757
/src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php @lyrixx
58-
/src/Symfony/Bundle/FrameworkBundle/Command/WorkflowDumpCommand.php @lyrixx
59-
/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ValidateWorkflowsPass.php @lyrixx
60-
/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/WorkflowGuardListenerPass.php @lyrixx
6158
/src/Symfony/Component/Workflow/ @lyrixx
6259
# Yaml
6360
/src/Symfony/Component/Yaml/ @xabbuh

UPGRADE-7.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ FrameworkBundle
5959
---------------
6060

6161
* Deprecate `Symfony\Bundle\FrameworkBundle\Console\Application::add()` in favor of `addCommand()`
62+
* Command `Symfony\Bundle\FrameworkBundle\Command\WorkflowDumpCommand` has been moved to `Symfony\Component\Workflow\Command\WorkflowDumpCommand`
6263

6364
HtmlSanitizer
6465
-------------

src/Symfony/Bundle/FrameworkBundle/Command/WorkflowDumpCommand.php

Lines changed: 4 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -12,120 +12,11 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

1414
use Symfony\Component\Console\Attribute\AsCommand;
15-
use Symfony\Component\Console\Command\Command;
16-
use Symfony\Component\Console\Completion\CompletionInput;
17-
use Symfony\Component\Console\Completion\CompletionSuggestions;
18-
use Symfony\Component\Console\Exception\InvalidArgumentException;
19-
use Symfony\Component\Console\Input\InputArgument;
20-
use Symfony\Component\Console\Input\InputInterface;
21-
use Symfony\Component\Console\Input\InputOption;
22-
use Symfony\Component\Console\Output\OutputInterface;
23-
use Symfony\Component\DependencyInjection\ServiceLocator;
24-
use Symfony\Component\Workflow\Debug\TraceableWorkflow;
25-
use Symfony\Component\Workflow\Dumper\GraphvizDumper;
26-
use Symfony\Component\Workflow\Dumper\MermaidDumper;
27-
use Symfony\Component\Workflow\Dumper\PlantUmlDumper;
28-
use Symfony\Component\Workflow\Dumper\StateMachineGraphvizDumper;
29-
use Symfony\Component\Workflow\Marking;
30-
use Symfony\Component\Workflow\StateMachine;
15+
use Symfony\Component\Workflow\Command\WorkflowDumpCommand as BaseWorkflowDumpCommand;
16+
17+
trigger_deprecation('symfony/framework-bundle', '7.4', 'The "%s" class is deprecated, use "%s" instead.', WorkflowDumpCommand::class, BaseWorkflowDumpCommand::class);
3118

32-
/**
33-
* @author Grégoire Pineau <lyrixx@lyrixx.info>
34-
*
35-
* @final
36-
*/
3719
#[AsCommand(name: 'workflow:dump', description: 'Dump a workflow')]
38-
class WorkflowDumpCommand extends Command
20+
class WorkflowDumpCommand extends BaseWorkflowDumpCommand
3921
{
40-
private const DUMP_FORMAT_OPTIONS = [
41-
'puml',
42-
'mermaid',
43-
'dot',
44-
];
45-
46-
public function __construct(
47-
private ServiceLocator $workflows,
48-
) {
49-
parent::__construct();
50-
}
51-
52-
protected function configure(): void
53-
{
54-
$this
55-
->setDefinition([
56-
new InputArgument('name', InputArgument::REQUIRED, 'A workflow name'),
57-
new InputArgument('marking', InputArgument::IS_ARRAY, 'A marking (a list of places)'),
58-
new InputOption('label', 'l', InputOption::VALUE_REQUIRED, 'Label a graph'),
59-
new InputOption('with-metadata', null, InputOption::VALUE_NONE, 'Include the workflow\'s metadata in the dumped graph', null),
60-
new InputOption('dump-format', null, InputOption::VALUE_REQUIRED, 'The dump format ['.implode('|', self::DUMP_FORMAT_OPTIONS).']', 'dot'),
61-
])
62-
->setHelp(<<<'EOF'
63-
The <info>%command.name%</info> command dumps the graphical representation of a
64-
workflow in different formats
65-
66-
<info>DOT</info>: %command.full_name% <workflow name> | dot -Tpng > workflow.png
67-
<info>PUML</info>: %command.full_name% <workflow name> --dump-format=puml | java -jar plantuml.jar -p > workflow.png
68-
<info>MERMAID</info>: %command.full_name% <workflow name> --dump-format=mermaid | mmdc -o workflow.svg
69-
EOF
70-
)
71-
;
72-
}
73-
74-
protected function execute(InputInterface $input, OutputInterface $output): int
75-
{
76-
$workflowName = $input->getArgument('name');
77-
78-
if (!$this->workflows->has($workflowName)) {
79-
throw new InvalidArgumentException(\sprintf('The workflow named "%s" cannot be found.', $workflowName));
80-
}
81-
$workflow = $this->workflows->get($workflowName);
82-
if ($workflow instanceof TraceableWorkflow) {
83-
$workflow = $workflow->getInner();
84-
}
85-
$type = $workflow instanceof StateMachine ? 'state_machine' : 'workflow';
86-
$definition = $workflow->getDefinition();
87-
88-
switch ($input->getOption('dump-format')) {
89-
case 'puml':
90-
$transitionType = 'workflow' === $type ? PlantUmlDumper::WORKFLOW_TRANSITION : PlantUmlDumper::STATEMACHINE_TRANSITION;
91-
$dumper = new PlantUmlDumper($transitionType);
92-
break;
93-
94-
case 'mermaid':
95-
$transitionType = 'workflow' === $type ? MermaidDumper::TRANSITION_TYPE_WORKFLOW : MermaidDumper::TRANSITION_TYPE_STATEMACHINE;
96-
$dumper = new MermaidDumper($transitionType);
97-
break;
98-
99-
case 'dot':
100-
default:
101-
$dumper = ('workflow' === $type) ? new GraphvizDumper() : new StateMachineGraphvizDumper();
102-
}
103-
104-
$marking = new Marking();
105-
106-
foreach ($input->getArgument('marking') as $place) {
107-
$marking->mark($place);
108-
}
109-
110-
$options = [
111-
'name' => $workflowName,
112-
'with-metadata' => $input->getOption('with-metadata'),
113-
'nofooter' => true,
114-
'label' => $input->getOption('label'),
115-
];
116-
$output->writeln($dumper->dump($definition, $marking, $options));
117-
118-
return 0;
119-
}
120-
121-
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
122-
{
123-
if ($input->mustSuggestArgumentValuesFor('name')) {
124-
$suggestions->suggestValues(array_keys($this->workflows->getProvidedServices()));
125-
}
126-
127-
if ($input->mustSuggestOptionValuesFor('dump-format')) {
128-
$suggestions->suggestValues(self::DUMP_FORMAT_OPTIONS);
129-
}
130-
}
13122
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
use Symfony\Bundle\FrameworkBundle\Command\SecretsSetCommand;
3838
use Symfony\Bundle\FrameworkBundle\Command\TranslationDebugCommand;
3939
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand;
40-
use Symfony\Bundle\FrameworkBundle\Command\WorkflowDumpCommand;
4140
use Symfony\Bundle\FrameworkBundle\Command\YamlLintCommand;
4241
use Symfony\Bundle\FrameworkBundle\Console\Application;
4342
use Symfony\Bundle\FrameworkBundle\EventListener\SuggestMissingPackageSubscriber;
@@ -61,6 +60,7 @@
6160
use Symfony\Component\Translation\Command\TranslationPushCommand;
6261
use Symfony\Component\Translation\Command\XliffLintCommand;
6362
use Symfony\Component\Validator\Command\DebugCommand as ValidatorDebugCommand;
63+
use Symfony\Component\Workflow\Command\WorkflowDumpCommand;
6464
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
6565

6666
return static function (ContainerConfigurator $container) {
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Workflow\Command;
13+
14+
use Symfony\Component\Console\Attribute\AsCommand;
15+
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Completion\CompletionInput;
17+
use Symfony\Component\Console\Completion\CompletionSuggestions;
18+
use Symfony\Component\Console\Exception\InvalidArgumentException;
19+
use Symfony\Component\Console\Input\InputArgument;
20+
use Symfony\Component\Console\Input\InputInterface;
21+
use Symfony\Component\Console\Input\InputOption;
22+
use Symfony\Component\Console\Output\OutputInterface;
23+
use Symfony\Component\DependencyInjection\ServiceLocator;
24+
use Symfony\Component\Workflow\Debug\TraceableWorkflow;
25+
use Symfony\Component\Workflow\Dumper\GraphvizDumper;
26+
use Symfony\Component\Workflow\Dumper\MermaidDumper;
27+
use Symfony\Component\Workflow\Dumper\PlantUmlDumper;
28+
use Symfony\Component\Workflow\Dumper\StateMachineGraphvizDumper;
29+
use Symfony\Component\Workflow\Marking;
30+
use Symfony\Component\Workflow\StateMachine;
31+
32+
/**
33+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
34+
*
35+
* @final
36+
*/
37+
#[AsCommand(name: 'workflow:dump', description: 'Dump a workflow')]
38+
class WorkflowDumpCommand extends Command
39+
{
40+
private const DUMP_FORMAT_OPTIONS = [
41+
'puml',
42+
'mermaid',
43+
'dot',
44+
];
45+
46+
public function __construct(
47+
private ServiceLocator $workflows,
48+
) {
49+
parent::__construct();
50+
}
51+
52+
protected function configure(): void
53+
{
54+
$this
55+
->setDefinition([
56+
new InputArgument('name', InputArgument::REQUIRED, 'A workflow name'),
57+
new InputArgument('marking', InputArgument::IS_ARRAY, 'A marking (a list of places)'),
58+
new InputOption('label', 'l', InputOption::VALUE_REQUIRED, 'Label a graph'),
59+
new InputOption('with-metadata', null, InputOption::VALUE_NONE, 'Include the workflow\'s metadata in the dumped graph', null),
60+
new InputOption('dump-format', null, InputOption::VALUE_REQUIRED, 'The dump format ['.implode('|', self::DUMP_FORMAT_OPTIONS).']', 'dot'),
61+
])
62+
->setHelp(<<<'EOF'
63+
The <info>%command.name%</info> command dumps the graphical representation of a
64+
workflow in different formats
65+
66+
<info>DOT</info>: %command.full_name% <workflow name> | dot -Tpng > workflow.png
67+
<info>PUML</info>: %command.full_name% <workflow name> --dump-format=puml | java -jar plantuml.jar -p > workflow.png
68+
<info>MERMAID</info>: %command.full_name% <workflow name> --dump-format=mermaid | mmdc -o workflow.svg
69+
EOF
70+
)
71+
;
72+
}
73+
74+
protected function execute(InputInterface $input, OutputInterface $output): int
75+
{
76+
$workflowName = $input->getArgument('name');
77+
78+
if (!$this->workflows->has($workflowName)) {
79+
throw new InvalidArgumentException(\sprintf('The workflow named "%s" cannot be found.', $workflowName));
80+
}
81+
$workflow = $this->workflows->get($workflowName);
82+
if ($workflow instanceof TraceableWorkflow) {
83+
$workflow = $workflow->getInner();
84+
}
85+
$type = $workflow instanceof StateMachine ? 'state_machine' : 'workflow';
86+
$definition = $workflow->getDefinition();
87+
88+
switch ($input->getOption('dump-format')) {
89+
case 'puml':
90+
$transitionType = 'workflow' === $type ? PlantUmlDumper::WORKFLOW_TRANSITION : PlantUmlDumper::STATEMACHINE_TRANSITION;
91+
$dumper = new PlantUmlDumper($transitionType);
92+
break;
93+
94+
case 'mermaid':
95+
$transitionType = 'workflow' === $type ? MermaidDumper::TRANSITION_TYPE_WORKFLOW : MermaidDumper::TRANSITION_TYPE_STATEMACHINE;
96+
$dumper = new MermaidDumper($transitionType);
97+
break;
98+
99+
case 'dot':
100+
default:
101+
$dumper = ('workflow' === $type) ? new GraphvizDumper() : new StateMachineGraphvizDumper();
102+
}
103+
104+
$marking = new Marking();
105+
106+
foreach ($input->getArgument('marking') as $place) {
107+
$marking->mark($place);
108+
}
109+
110+
$options = [
111+
'name' => $workflowName,
112+
'with-metadata' => $input->getOption('with-metadata'),
113+
'nofooter' => true,
114+
'label' => $input->getOption('label'),
115+
];
116+
$output->writeln($dumper->dump($definition, $marking, $options));
117+
118+
return 0;
119+
}
120+
121+
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
122+
{
123+
if ($input->mustSuggestArgumentValuesFor('name')) {
124+
$suggestions->suggestValues(array_keys($this->workflows->getProvidedServices()));
125+
}
126+
127+
if ($input->mustSuggestOptionValuesFor('dump-format')) {
128+
$suggestions->suggestValues(self::DUMP_FORMAT_OPTIONS);
129+
}
130+
}
131+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Command/WorkflowDumpCommandTest.php renamed to src/Symfony/Component/Workflow/Tests/Command/WorkflowDumpCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
12+
namespace Symfony\Component\Workflow\Tests\Command;
1313

1414
use PHPUnit\Framework\Attributes\DataProvider;
1515
use PHPUnit\Framework\TestCase;
16-
use Symfony\Bundle\FrameworkBundle\Command\WorkflowDumpCommand;
1716
use Symfony\Component\Console\Application;
1817
use Symfony\Component\Console\Tester\CommandCompletionTester;
1918
use Symfony\Component\DependencyInjection\ServiceLocator;
19+
use Symfony\Component\Workflow\Command\WorkflowDumpCommand;
2020

2121
class WorkflowDumpCommandTest extends TestCase
2222
{

0 commit comments

Comments
 (0)