8000 [Workflow] Changed initial_places to initial_marking, added property by lyrixx · Pull Request #30890 · symfony/symfony · GitHub
[go: up one dir, main page]

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 all commits
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
44 changes: 35 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,44 @@ 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
```

* Using a workflow with a single state marking is deprecated. Use a state machine instead.

Before:
```yaml
framework:
workflows:
article:
type: workflow
marking_store:
type: single_state
```

After:
```yaml
framework:
workflows:
article:
type: state_machine
marking_store:
# type: single_state # Since the single_state marking store is deprecated, use method instead
type: method
```

Yaml
----

* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.
64 changes: 62 additions & 2 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,68 @@ 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
```


* Support for using a workflow with a single state marking is dropped. Use a state machine instead.

Before:
```yaml
framework:
workflows:
article:
type: workflow
marking_store:
type: single_state
```

After:
```yaml
framework:
workflows:
article:
type: state_machine
```

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 @@ -275,8 +283,17 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->children()
->enumNode('type')
->values(['multiple_state', 'single_state', 'method'])
->validate()
->ifTrue(function ($v) { return 'method' !== $v; })
->then(function ($v) {
@trigger_error('Passing something else than "method" has been deprecated in Symfony 4.3.', E_USER_DEPRECATED);

return $v;
})
->end()
->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 +302,9 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->prototype('scalar')
->end()
->end()
->scalarNode('property')
->defaultValue('marking')
->end()
->scalarNode('service')
->cannotBeEmpty()
->end()
Expand Down Expand Up @@ -315,10 +335,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 @@ -454,6 +474,16 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
})
->thenInvalid('"supports" or "support_strategy" should be configured.')
->end()
->validate()
->ifTrue(function ($v) {
return 'workflow' === $v['type'] && 'single_state' === ($v['marking_store']['type'] ?? false);
})
->then(function ($v) {
@trigger_error('Using a workflow with type=workflow and a marking_store=single_state is deprecated since Symfony 4.3. Use type=state_machine instead.', E_USER_DEPRECATED);

return $v;
})
->end()
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,21 +631,28 @@ 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
if (isset($workflow['marking_store']['type'])) {
$markingStoreDefinition = new ChildDefinition('workflow.marking_store.'.$workflow['marking_store']['type']);
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'],
]);
} else {
foreach ($workflow['marking_store']['arguments'] as $argument) {
$markingStoreDefinition->addArgument($argument);
}
}
} elseif (isset($workflow['marking_store']['service'])) {
$markingStoreDefinition = new Reference($workflow['marking_store']['service']);
Expand All @@ -670,23 +677,20 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
case 'state_machine' === $workflow['type']:
$validator = new Workflow\Validator\StateMachineValidator();
break;
case 'method' === ($workflow['marking_store']['type'] ?? null):
$singlePlace = $workflow['marking_store']['arguments'][0] ?? false;
$validator = new Workflow\Validator\WorkflowValidator($singlePlace);
break;
case 'single_state' === ($workflow['marking_store']['type'] ?? null):
$validator = new Workflow\Validator\WorkflowValidator(true);
break;
case 'multiple_state' === ($workflow['marking_store']['type'] ?? false):
$validator = new Workflow\Validator\WorkflowValidator(false);
break;
}

if ($validator) {
$realDefinition = (new Workflow\DefinitionBuilder($places))
->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,11 +1,15 @@
<?php

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

$container->loadFromExtension('framework', [
'workflows' => [
'legacy' => [
'type' => 'workflow',
'type' => 'state_machine',
'marking_store' => [
'type' => 'single_state',
'arguments' => [
'state',
],
],
'supports' => [
stdClass::class,
],
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
Loading
0