Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c91773

Browse files
committed
[Workflow] Add support for storing the marking in a property
1 parent 86c41bb commit 3c91773

File tree

16 files changed

+276
-14
lines changed

16 files changed

+276
-14
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add native return type to `Translator` and to `Application::reset()`
88
* Deprecate the integration of Doctrine annotations, either uninstall the `doctrine/annotations` package or disable the integration by setting `framework.annotations` to `false`
9+
* Add support for `PropertiesMarkingStore` in the workflow configuration
910

1011
6.3
1112
---

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,14 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
403403
->arrayNode('marking_store')
404404
->children()
405405
->enumNode('type')
406-
->values(['method'])
406+
->values(['method', 'properties'])
407407
->end()
408408
->scalarNode('property')
409409
->defaultValue('marking')
410410
->end()
411+
->scalarNode('context_property')
412+
->defaultValue('markingContext')
413+
->end()
411414
->scalarNode('service')
412415
->cannotBeEmpty()
413416
->end()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,12 +998,20 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
998998

999999
// Create MarkingStore
10001000
$markingStoreDefinition = null;
1001-
if (isset($workflow['marking_store']['type'])) {
1001+
$markingStoreType = $workflow['marking_store']['type'] ?? null;
1002+
if ('method' === $markingStoreType) {
10021003
$markingStoreDefinition = new ChildDefinition('workflow.marking_store.method');
10031004
$markingStoreDefinition->setArguments([
10041005
'state_machine' === $type, // single state
10051006
$workflow['marking_store']['property'],
10061007
]);
1008+
} elseif ('properties' === $markingStoreType) {
1009+
$markingStoreDefinition = new ChildDefinition('workflow.marking_store.properties');
1010+
$markingStoreDefinition->setArguments([
1011+
'state_machine' === $type, // single state
1012+
$workflow['marking_store']['property'],
1013+
$workflow['marking_store']['context_property'],
1014+
]);
10071015
} elseif (isset($workflow['marking_store']['service'])) {
10081016
$markingStoreDefinition = new Reference($workflow['marking_store']['service']);
10091017
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,13 @@
443443
<xsd:attribute name="type" type="marking_store_type" />
444444
<xsd:attribute name="service" type="xsd:string" />
445445
<xsd:attribute name="property" type="xsd:string" />
446+
<xsd:attribute name="context_property" type="xsd:string" />
446447
</xsd:complexType>
447448

448449
<xsd:simpleType name="marking_store_type">
449450
<xsd:restriction base="xsd:string">
450451
<xsd:enumeration value="method" />
452+
<xsd:enumeration value="properties" />
451453
</xsd:restriction>
452454
</xsd:simpleType>
453455

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Workflow\EventListener\ExpressionLanguage;
1515
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
16+
use Symfony\Component\Workflow\MarkingStore\PropertiesMarkingStore;
1617
use Symfony\Component\Workflow\Registry;
1718
use Symfony\Component\Workflow\StateMachine;
1819
use Symfony\Component\Workflow\Workflow;
@@ -39,6 +40,8 @@
3940
->abstract()
4041
->set('workflow.marking_store.method', MethodMarkingStore::class)
4142
->abstract()
43+
->set('workflow.marking_store.properties', PropertiesMarkingStore::class)
44+
->abstract()
4245
->set('.workflow.registry', Registry::class)
4346
->alias(Registry::class, '.workflow.registry')
4447
->deprecate('symfony/workflow', '6.2', 'The "%alias_id%" alias is deprecated, inject the workflow directly.')

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
FrameworkExtensionTestCase::class,
4949
],
5050
'initial_marking' => 'start',
51+
'marking_store' => [
52+
'type' => 'properties',
53+
'property' => 'state',
54+
'context_property' => 'stateContext',
55+
],
5156
'metadata' => [
5257
'title' => 'workflow title',
5358
],

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<framework:workflow name="pull_request">
4646
<framework:audit-trail enabled="false"/>
4747
<framework:initial-marking>start</framework:initial-marking>
48+
<framework:marking-store type="properties" property="state" context_property="stateContext" />
4849
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTestCase</framework:support>
4950
<framework:place name="start">
5051
<framework:metadata>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ framework:
3535
supports:
3636
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTestCase
3737
initial_marking: start
38+
marking_store:
39+
type: properties
40+
property: state
41+
context_property: stateContext
3842
metadata:
3943
title: workflow title
4044
places:

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ public function testWorkflows()
300300
$args = $container->getDefinition('workflow.article')->getArguments();
301301
$this->assertArrayHasKey('index_0', $args);
302302
$this->assertArrayHasKey('index_1', $args);
303+
$this->assertNull($args['index_1']);
303304
$this->assertArrayHasKey('index_3', $args);
304305
$this->assertArrayHasKey('index_4', $args);
305306
$this->assertNull($args['index_4'], 'Workflows has eventsToDispatch=null');
@@ -333,6 +334,12 @@ public function testWorkflows()
333334

334335
$this->assertTrue($container->hasDefinition('state_machine.pull_request'), 'State machine is registered as a service');
335336
$this->assertSame('state_machine.abstract', $container->getDefinition('state_machine.pull_request')->getParent());
337+
338+
$markingStoreDefinition = $container->getDefinition('state_machine.pull_request')->getArguments()['index_1'];
339+
$this->assertInstanceOf(ChildDefinition::class, $markingStoreDefinition);
340+
$this->assertSame('workflow.marking_store.properties', $markingStoreDefinition->getParent());
341+
$this->assertSame([true, 'state', 'stateContext'], $markingStoreDefinition->getArguments());
342+
336343
$this->assertTrue($container->hasDefinition('state_machine.pull_request.definition'), 'State machine definition is registered as a service');
337344

338345
$this->assertSame(['workflow' => [['name' => 'pull_request']], 'workflow.state_machine' => [['name' => 'pull_request']]], $container->getDefinition('state_machine.pull_request')->getTags());

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"symfony/twig-bundle": "<5.4",
100100
"symfony/validator": "<6.3",
101101
"symfony/web-profiler-bundle": "<5.4",
102-
"symfony/workflow": "<5.4"
102+
"symfony/workflow": "<6.4"
103103
},
104104
"autoload": {
105105
"psr-4": { "Symfony\\Bundle\\FrameworkBundle\\": "" },

0 commit comments

Comments
 (0)