Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb2cbe22

Browse files
committed
[Workflow] Added a context toWorkflow::apply()
1 parentc7fe1b6 commitb2cbe22

File tree

13 files changed

+176
-13
lines changed

13 files changed

+176
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
267267
->fixXmlConfig('argument')
268268
->children()
269269
->enumNode('type')
270-
->values(array('multiple_state','single_state'))
270+
->values(array('multiple_state','single_state','method'))
271271
->end()
272272
->arrayNode('arguments')
273273
->beforeNormalization()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,8 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
594594
$definitionDefinition->addTag('workflow.definition',array(
595595
'name' =>$name,
596596
'type' =>$type,
597-
'marking_store' =>isset($workflow['marking_store']['type']) ?$workflow['marking_store']['type'] :null,
597+
'marking_store' =>$workflow['marking_store']['type'] ??null,
598+
'single_state' =>'method' === ($workflow['marking_store']['type'] ??null) && ($workflow['marking_store']['arguments'][0] ??false),
598599
));
599600

600601
// Create MarkingStore

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/workflow.xml‎

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

2323
<serviceid="workflow.marking_store.multiple_state"class="Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore"abstract="true" />
2424
<serviceid="workflow.marking_store.single_state"class="Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore"abstract="true" />
25+
<serviceid="workflow.marking_store.method"class="Symfony\Component\Workflow\MarkingStore\MethodMarkingStore"abstract="true" />
2526

2627
<serviceid="workflow.registry"class="Symfony\Component\Workflow\Registry" />
2728
<serviceid="Symfony\Component\Workflow\Registry"alias="workflow.registry" />

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public function testWorkflows()
215215
$workflowDefinition->getArgument(0),
216216
'Places are passed to the workflow definition'
217217
);
218-
$this->assertSame(array('workflow.definition' =>array(array('name' =>'article','type' =>'workflow','marking_store' =>'multiple_state'))),$workflowDefinition->getTags());
218+
$this->assertSame(array('workflow.definition' =>array(array('name' =>'article','type' =>'workflow','marking_store' =>'multiple_state','single_state' =>false))),$workflowDefinition->getTags());
219219
$this->assertCount(4,$workflowDefinition->getArgument(1));
220220
$this->assertSame('draft',$workflowDefinition->getArgument(2));
221221

@@ -237,7 +237,7 @@ public function testWorkflows()
237237
$stateMachineDefinition->getArgument(0),
238238
'Places are passed to the state machine definition'
239239
);
240-
$this->assertSame(array('workflow.definition' =>array(array('name' =>'pull_request','type' =>'state_machine','marking_store' =>'single_state'))),$stateMachineDefinition->getTags());
240+
$this->assertSame(array('workflow.definition' =>array(array('name' =>'pull_request','type' =>'state_machine','marking_store' =>'single_state','single_state' =>false))),$stateMachineDefinition->getTags());
241241
$this->assertCount(9,$stateMachineDefinition->getArgument(1));
242242
$this->assertSame('start',$stateMachineDefinition->getArgument(2));
243243

‎src/Symfony/Component/Workflow/CHANGELOG.md‎

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

77
* Trigger`entered` event for subject entering in the Workflow for the first time
8+
* Added a context to`Workflow::apply()`. The`MethodMarkingStore` could be used to leverage this feature.
89

910
4.1.0
1011
-----

‎src/Symfony/Component/Workflow/DependencyInjection/ValidateWorkflowsPass.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ private function createValidator($tag)
5959
returnnewWorkflowValidator(true);
6060
}
6161

62-
returnnewWorkflowValidator();
62+
if ('multiple_state' ===$tag['marking_store']) {
63+
returnnewWorkflowValidator(false);
64+
}
65+
66+
returnnewWorkflowValidator($tag['single_state'] ??false);
6367
}
6468
}

‎src/Symfony/Component/Workflow/MarkingStore/MarkingStoreInterface.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public function getMarking($subject);
3636
/**
3737
* Sets a Marking to a subject.
3838
*
39-
* @param object $subject A subject
40-
* @param Marking $marking A marking
39+
* @param object $subject A subject
4140
*/
42-
publicfunctionsetMarking($subject,Marking$marking);
41+
publicfunctionsetMarking($subject,Marking$marking,array$context =array());
4342
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Workflow\MarkingStore;
13+
14+
useSymfony\Component\Workflow\Exception\LogicException;
15+
useSymfony\Component\Workflow\Marking;
16+
17+
/**
18+
* MethodMarkingStore stores the marking with a subject's method.
19+
*
20+
* This store deals with a "single state" or "multiple state" Marking.
21+
*
22+
* @author Grégoire Pineau <lyrixx@lyrixx.info>
23+
*/
24+
class MethodMarkingStoreimplements MarkingStoreInterface
25+
{
26+
private$singleState;
27+
private$property;
28+
29+
/**
30+
* @param string $property Used to determine methods to call
31+
* The `getMarking` method will use `$subject->getProperty()`
32+
* The `setMarking` method will use `$subject->setProperty(string|array $places, array $context = array())`
33+
*/
34+
publicfunction__construct(bool$singleState =false,string$property ='marking')
35+
{
36+
$this->singleState =$singleState;
37+
$this->property =$property;
38+
}
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
publicfunctiongetMarking($subject)
44+
{
45+
$method ='get'.ucfirst($this->property);
46+
47+
if (!method_exists($subject,$method)) {
48+
thrownewLogicException(sprintf('The method "%s::%s()" does not exists.',\get_class($subject),$method));
49+
}
50+
51+
$marking =$subject->{$method}();
52+
53+
if (!$marking) {
54+
returnnewMarking();
55+
}
56+
57+
if ($this->singleState) {
58+
$marking =array($marking =>1);
59+
}
60+
61+
returnnewMarking($marking);
62+
}
63+
64+
/**
65+
* {@inheritdoc}
66+
*/
67+
publicfunctionsetMarking($subject,Marking$marking,array$context =array())
68+
{
69+
$marking =$marking->getPlaces();
70+
71+
if ($this->singleState) {
72+
$marking =key($marking);
73+
}
74+
75+
$method ='set'.ucfirst($this->property);
76+
77+
if (!method_exists($subject,$method)) {
78+
thrownewLogicException(sprintf('The method "%s::%s()" does not exists.',\get_class($subject),$method));
79+
}
80+
81+
$subject->{$method}($marking,$context);
82+
}
83+
}

‎src/Symfony/Component/Workflow/MarkingStore/MultipleStateMarkingStore.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getMarking($subject)
4646
/**
4747
* {@inheritdoc}
4848
*/
49-
publicfunctionsetMarking($subject,Marking$marking)
49+
publicfunctionsetMarking($subject,Marking$marking,array$context =array())
5050
{
5151
$this->propertyAccessor->setValue($subject,$this->property,$marking->getPlaces());
5252
}

‎src/Symfony/Component/Workflow/MarkingStore/SingleStateMarkingStore.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getMarking($subject)
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
publicfunctionsetMarking($subject,Marking$marking)
54+
publicfunctionsetMarking($subject,Marking$marking,array$context =array())
5555
{
5656
$this->propertyAccessor->setValue($subject,$this->property,key($marking->getPlaces()));
5757
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp