Skip to content

Commit

Permalink
[Workflow] Changed initial_places to initial_marking, added property …
Browse files Browse the repository at this point in the history
…instead of type
  • Loading branch information
HeahDude authored and Jules Pietri committed Mar 26, 2019
1 parent 0034a0f commit 95bc4ef
Show file tree
Hide file tree
Showing 38 changed files with 214 additions and 98 deletions.
21 changes: 12 additions & 9 deletions UPGRADE-4.3.md
Expand Up @@ -147,11 +147,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 @@ -183,19 +178,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 @@ -206,16 +204,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
Expand Up @@ -369,8 +369,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
Expand Up @@ -231,7 +231,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 @@ -256,9 +256,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 @@ -272,9 +280,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 @@ -283,6 +293,9 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->prototype('scalar')
->end()
->end()
->scalarNode('property')
->defaultNull()
->end()
->scalarNode('service')
->cannotBeEmpty()
->end()
Expand All @@ -295,6 +308,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 @@ -313,10 +330,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
Expand Up @@ -621,14 +621,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 @@ -637,6 +637,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 @@ -676,7 +682,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
Expand Up @@ -270,7 +270,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 @@ -280,6 +280,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 @@ -295,12 +296,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
@@ -1,7 +1,5 @@
<?php

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

$container->loadFromExtension('framework', [
'workflows' => [
'legacy' => [
Expand Down
Expand Up @@ -6,7 +6,7 @@
'workflows' => [
'my_workflow' => [
'marking_store' => [
'type' => 'multiple_state',
'type' => 'method',
'service' => 'workflow_service',
],
'supports' => [
Expand Down
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 @@ -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
@@ -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',
],
],
],
],
],
]);
Expand Up @@ -5,9 +5,7 @@
$container->loadFromExtension('framework', [
'workflows' => [
'my_workflow' => [
'marking_store' => [
'type' => 'multiple_state',
],
'type' => 'workflow',
'supports' => [
FrameworkExtensionTest::class,
],
Expand Down
@@ -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
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

0 comments on commit 95bc4ef

Please sign in to comment.