Skip to content

[Workflow] Changed initial_places to initial_marking, added property #30890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Workflow] Changed initial_places to initial_marking, added property …
…instead of type
  • Loading branch information
HeahDude authored and lyrixx committed Apr 6, 2019
commit 73708a61b6af18f41b8a398645c31e7ca688205c
21 changes: 12 additions & 9 deletions UPGRADE-4.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ Workflow
initial_places: [draft]
```

Yaml
----

* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.

Workflow
--------

Expand Down Expand Up @@ -202,19 +197,22 @@ Workflow
```yaml
framework:
workflows:
type: workflow
article:
marking_store:
type: multiple
arguments: states
```

After:
```yaml
framework:
workflows:
type: workflow
article:
marking_store:
type: method

property: states
```

* `SingleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead.
Expand All @@ -225,16 +223,21 @@ Workflow
workflows:
article:
marking_store:
type: single
arguments: state
```

After:
```yaml
framework:
workflows:
type: state_machine
article:
marking_store:
type: method
arguments:
- true
property: state
```

Yaml
----

* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.
43 changes: 41 additions & 2 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,47 @@ Workflow
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
* Removed support of `initial_place`. Use `initial_places` instead.
* `MultipleStateMarkingStore` has been removed.
* `SingleStateMarkingStore` has been removed.
* `MultipleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead.

Before:
```yaml
framework:
workflows:
type: workflow
article:
marking_store:
type: multiple
arguments: states
```

After:
```yaml
framework:
workflows:
type: workflow
article:
marking_store:
property: states
```
* `SingleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead.

Before:
```yaml
framework:
workflows:
article:
marking_store:
arguments: state
```

After:
```yaml
framework:
workflows:
article:
marking_store:
property: state
```

Yaml
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
$workflows = [];
}

if (1 === \count($workflows) && isset($workflows['workflows']) && array_keys($workflows['workflows']) !== range(0, \count($workflows) - 1) && !empty(array_diff(array_keys($workflows['workflows']), ['audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_places', 'places', 'transitions']))) {
if (1 === \count($workflows) && isset($workflows['workflows']) && array_keys($workflows['workflows']) !== range(0, \count($workflows) - 1) && !empty(array_diff(array_keys($workflows['workflows']), ['audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_marking', 'places', 'transitions']))) {
$workflows = $workflows['workflows'];
}

Expand All @@ -258,9 +258,17 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->arrayNode('workflows')
->useAttributeAsKey('name')
->prototype('array')
->beforeNormalization()
->always(function ($v) {
if (isset($v['initial_place'])) {
$v['initial_marking'] = [$v['initial_place']];
}

return $v;
})
->end()
->fixXmlConfig('support')
->fixXmlConfig('place')
->fixXmlConfig('initial_place')
->fixXmlConfig('transition')
->children()
->arrayNode('audit_trail')
Expand All @@ -274,9 +282,11 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->fixXmlConfig('argument')
->children()
->enumNode('type')
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "method" instead as it will be the only option in Symfony 5.0.')
->values(['multiple_state', 'single_state', 'method'])
->end()
->arrayNode('arguments')
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "property" instead.')
->beforeNormalization()
->ifString()
->then(function ($v) { return [$v]; })
Expand All @@ -285,6 +295,9 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->prototype('scalar')
->end()
->end()
->scalarNode('property')
->defaultNull()
->end()
->scalarNode('service')
->cannotBeEmpty()
->end()
Expand All @@ -297,6 +310,10 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->ifTrue(function ($v) { return !empty($v['arguments']) && isset($v['service']); })
->thenInvalid('"arguments" and "service" cannot be used together.')
->end()
->validate()
->ifTrue(function ($v) { return !empty($v['property']) && isset($v['service']); })
->thenInvalid('"property" and "service" cannot be used together.')
->end()
->end()
->arrayNode('supports')
->beforeNormalization()
Expand All @@ -315,10 +332,10 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->cannotBeEmpty()
->end()
->scalarNode('initial_place')
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_places" configuration key instead.')
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_marking" configuration key instead.')
->defaultNull()
->end()
->arrayNode('initial_places')
->arrayNode('initial_marking')
->beforeNormalization()
->ifTrue(function ($v) { return !\is_array($v); })
->then(function ($v) { return [$v]; })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,14 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $

// Create places
$places = array_column($workflow['places'], 'name');
$initialPlaces = $workflow['initial_places'] ?? $workflow['initial_place'] ?? [];
$initialMarking = $workflow['initial_marking'] ?? $workflow['initial_place'] ?? [];

// Create a Definition
$definitionDefinition = new Definition(Workflow\Definition::class);
$definitionDefinition->setPublic(false);
$definitionDefinition->addArgument($places);
$definitionDefinition->addArgument($transitions);
$definitionDefinition->addArgument($initialPlaces);
$definitionDefinition->addArgument($initialMarking);
$definitionDefinition->addArgument($metadataStoreDefinition);

// Create MarkingStore
Expand All @@ -647,6 +647,12 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
foreach ($workflow['marking_store']['arguments'] as $argument) {
$markingStoreDefinition->addArgument($argument);
}
if ('method' === $workflow['marking_store']['type']) {
$markingStoreDefinition->setArguments([
'state_machine' === $type, //single state
$workflow['marking_store']['property'] ?? 'marking',
]);
}
} elseif (isset($workflow['marking_store']['service'])) {
$markingStoreDefinition = new Reference($workflow['marking_store']['service']);
}
Expand Down Expand Up @@ -686,7 +692,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition {
return $container->get((string) $ref);
}, $transitions))
->setInitialPlace($initialPlaces)
->setInitialPlace($initialMarking)
->build()
;
$validator->validate($realDefinition, $name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@

<xsd:complexType name="workflow">
<xsd:sequence>
<xsd:element name="initial-place" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="initial-marking" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="marking-store" type="marking_store" minOccurs="0" maxOccurs="1" />
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="place" type="place" minOccurs="0" maxOccurs="unbounded" />
Expand All @@ -289,6 +289,7 @@
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="workflow_type" />
<xsd:attribute name="initial-place" type="xsd:string" />
<xsd:attribute name="initial-marking" type="xsd:string" />
<xsd:attribute name="support-strategy" type="xsd:string" />
<xsd:attribute name="enabled" type="xsd:boolean" />
</xsd:complexType>
Expand All @@ -304,12 +305,14 @@
</xsd:sequence>
<xsd:attribute name="type" type="marking_store_type" />
<xsd:attribute name="service" type="xsd:string" />
<xsd:attribute name="property" type="xsd:string" />
</xsd:complexType>

<xsd:simpleType name="marking_store_type">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="multiple_state" />
<xsd:enumeration value="single_state" />
<xsd:enumeration value="method" />
</xsd:restriction>
</xsd:simpleType>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;

$container->loadFromExtension('framework', [
'workflows' => [
'legacy' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'workflows' => [
'my_workflow' => [
'marking_store' => [
'type' => 'multiple_state',
'type' => 'method',
'service' => 'workflow_service',
],
'supports' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
'workflows' => [
'article' => [
'type' => 'workflow',
'marking_store' => [
'type' => 'multiple_state',
],
'supports' => [
FrameworkExtensionTest::class,
],
'initial_places' => ['draft'],
'initial_marking' => ['draft'],
'places' => [
'draft',
'wait_for_journalist',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
'workflows' => [
'article' => [
'type' => 'workflow',
'marking_store' => [
'type' => 'multiple_state',
],
'supports' => [
FrameworkExtensionTest::class,
],
'initial_places' => ['draft'],
'initial_marking' => ['draft'],
'places' => [
'draft',
'wait_for_journalist',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;

$container->loadFromExtension('framework', [
'workflows' => [
'my_workflow' => [
'type' => 'workflow',
'marking_store' => [
'property' => 'states',
'service' => 'workflow_service',
],
'supports' => [
FrameworkExtensionTest::class,
],
'places' => [
'first',
'last',
],
'transitions' => [
'go' => [
'from' => [
'first',
],
'to' => [
'last',
],
],
],
],
],
]);
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
$container->loadFromExtension('framework', [
'workflows' => [
'my_workflow' => [
'marking_store' => [
'type' => 'multiple_state',
],
'type' => 'workflow',
'supports' => [
FrameworkExtensionTest::class,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?php

use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;

$container->loadFromExtension('framework', [
'workflows' => [
'my_workflow' => [
'marking_store' => [
'type' => 'multiple_state',
],
'type' => 'workflow',
'places' => [
'first',
'last',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
'workflows' => [
'article' => [
'type' => 'workflow',
'marking_store' => [
'type' => 'multiple_state',
],
'supports' => [
FrameworkExtensionTest::class,
],
'initial_places' => ['draft'],
'initial_marking' => ['draft'],
'places' => [
'draft',
'wait_for_journalist',
Expand Down Expand Up @@ -41,13 +38,10 @@
],
],
'pull_request' => [
'marking_store' => [
'type' => 'single_state',
],
'supports' => [
FrameworkExtensionTest::class,
],
'initial_places' => ['start'],
'initial_marking' => 'start',
'metadata' => [
'title' => 'workflow title',
],
Expand Down
Loading