Skip to content

Commit 152611b

Browse files
committed
[Workflow] Made the code more robbust and ease on-boarding
1 parent 2a6af4e commit 152611b

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

DependencyInjection/Compiler/ValidateWorkflowsPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public function process(ContainerBuilder $container)
3535
foreach ($taggedServices as $id => $tags) {
3636
$definition = $container->get($id);
3737
foreach ($tags as $tag) {
38-
if (empty($tag['name'])) {
38+
if (!array_key_exists('name', $tag)) {
3939
throw new RuntimeException(sprintf('The "name" for the tag "workflow.definition" of service "%s" must be set.', $id));
4040
}
41-
if (empty($tag['type'])) {
41+
if (!array_key_exists('type', $tag)) {
4242
throw new RuntimeException(sprintf('The "type" for the tag "workflow.definition" of service "%s" must be set.', $id));
4343
}
44-
if (empty($tag['marking_store'])) {
44+
if (!array_key_exists('marking_store', $tag)) {
4545
throw new RuntimeException(sprintf('The "marking_store" for the tag "workflow.definition" of service "%s" must be set.', $id));
4646
}
4747

DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
425425
foreach ($workflow['marking_store']['arguments'] as $argument) {
426426
$markingStoreDefinition->addArgument($argument);
427427
}
428-
} else {
428+
} elseif (isset($workflow['marking_store']['service'])) {
429429
$markingStoreDefinition = new Reference($workflow['marking_store']['service']);
430430
}
431431

@@ -438,7 +438,9 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
438438

439439
$workflowDefinition = new DefinitionDecorator(sprintf('%s.abstract', $type));
440440
$workflowDefinition->replaceArgument(0, $definitionDefinition);
441-
$workflowDefinition->replaceArgument(1, $markingStoreDefinition);
441+
if (isset($markingStoreDefinition)) {
442+
$workflowDefinition->replaceArgument(1, $markingStoreDefinition);
443+
}
442444
$workflowDefinition->replaceArgument(3, $name);
443445

444446
$workflowId = sprintf('%s.%s', $type, $name);

Resources/config/workflow.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
<services>
88
<service id="workflow.abstract" class="Symfony\Component\Workflow\Workflow" abstract="true">
99
<argument /> <!-- workflow definition -->
10-
<argument /> <!-- marking store -->
10+
<argument type="constant">null</argument> <!-- marking store -->
1111
<argument type="service" id="event_dispatcher" on-invalid="ignore" />
1212
<argument /> <!-- name -->
1313
</service>
1414
<service id="state_machine.abstract" class="Symfony\Component\Workflow\StateMachine" abstract="true">
1515
<argument /> <!-- workflow definition -->
16-
<argument /> <!-- marking store -->
16+
<argument type="constant">null</argument> <!-- marking store -->
1717
<argument type="service" id="event_dispatcher" on-invalid="ignore" />
1818
<argument /> <!-- name -->
1919
</service>

0 commit comments

Comments
 (0)