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

Commit4814896

Browse files
committed
Added a TransitionsCollectionBuilder
1 parent69aff45 commit4814896

File tree

2 files changed

+105
-17
lines changed

2 files changed

+105
-17
lines changed

‎src/Symfony/Component/Workflow/DefinitionBuilder.php‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class DefinitionBuilder
2424
{
2525
private$places =array();
26-
private$transitions =array();
26+
private$transitions;
2727
private$initialPlace;
2828

2929
/**
@@ -35,15 +35,16 @@ class DefinitionBuilder
3535
publicfunction__construct(array$places =array(),array$transitions =array())
3636
{
3737
$this->addPlaces($places);
38-
$this->addTransitions($transitions);
38+
$this->transitions =newTransitionsCollectionBuilder();
39+
$this->transitions->addTransitions($transitions);
3940
}
4041

4142
/**
4243
* @return Definition
4344
*/
4445
publicfunctionbuild()
4546
{
46-
returnnewDefinition($this->places,$this->transitions,$this->initialPlace);
47+
returnnewDefinition($this->places,$this->transitions->getTransitions(),$this->initialPlace);
4748
}
4849

4950
/**
@@ -52,7 +53,7 @@ public function build()
5253
publicfunctionreset()
5354
{
5455
$this->places =array();
55-
$this->transitions =array();
56+
$this->transitions =$this->transitions->reset();
5657
$this->initialPlace =null;
5758
}
5859

@@ -88,14 +89,7 @@ public function addPlaces(array $places)
8889
*/
8990
publicfunctionaddTransitions(array$transitions)
9091
{
91-
foreach ($transitionsas$transition) {
92-
if ($transitioninstanceof Transition) {
93-
$this->addTransition($transition);
94-
}else {
95-
list($name,$froms,$tos) =$transition;
96-
$this->addTransition($name,$froms,$tos);
97-
}
98-
}
92+
$this->transitions->addTransitions($transitions);
9993
}
10094

10195
/**
@@ -105,10 +99,6 @@ public function addTransitions(array $transitions)
10599
*/
106100
publicfunctionaddTransition($transition,$froms =null,$tos =null)
107101
{
108-
if ($transitioninstanceof Transition) {
109-
$this->transitions[] =$transition;
110-
}else {
111-
$this->transitions[] =newTransition($transition,$froms,$tos);
112-
}
102+
$this->transitions->addTransition($transition,$froms,$tos);
113103
}
114104
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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;
13+
14+
useSymfony\Component\Workflow\Exception\InvalidArgumentException;
15+
useSymfony\Component\Workflow\Exception\LogicException;
16+
17+
/**
18+
* TransitionsCollectionBuilder.
19+
*
20+
* @author Jules Pietri <jules@heahprod.com>
21+
*/
22+
class TransitionsCollectionBuilder
23+
{
24+
private$transitions =array();
25+
26+
/**
27+
* @param Transition|string $transition
28+
* @param string[]string $froms
29+
* @param string[]string $tos
30+
*/
31+
publicfunctionaddTransition($transition,$froms,$tos)
32+
{
33+
if ($transitioninstanceof Transition) {
34+
$this->add($transition);
35+
36+
return;
37+
}
38+
39+
if (empty($froms)) {
40+
thrownewLogicException(sprintf('The transition "%" is missing "froms" place(s).',$transition));
41+
}
42+
if (empty($to)) {
43+
thrownewLogicException(sprintf('The transition "%" is missing "tos" place(s).',$transition));
44+
}
45+
46+
$this->createTransition($transition,$froms,$tos);
47+
}
48+
49+
/**
50+
* @param array[] $transitions An array of three arguments to pass to "addTransition"
51+
*/
52+
publicfunctionaddTransitions(array$transitions)
53+
{
54+
foreach ($transitionsas$transition) {
55+
if ($transitioninstanceof Transition) {
56+
$this->add($transition);
57+
58+
continue;
59+
}
60+
61+
if (!is_array($transition) ||3 ===count($transitions)) {
62+
thrownewInvalidArgumentException(sprintf(
63+
'Calling "%" expected each entry to be an instance of "%s" or an array of three arguments to create a transition instance%s: "name", "froms", and "tos", but got %s.',
64+
__METHOD__,
65+
Transition::class,
66+
isset($transition[0]) ?' named "'.$transition[0].'"' :'',
67+
is_array($transition) ?' an array with'.count($transition).' entries' :gettype($transition)));
68+
}
69+
list($name,$froms,$tos) =$transition;
70+
$this->addTransition($name,$froms,$tos);
71+
}
72+
}
73+
74+
publicfunctiongetTransitions()
75+
{
76+
return$this->transitions;
77+
}
78+
79+
publicfunctionreset()
80+
{
81+
return$this->transitions =array();
82+
}
83+
84+
privatefunctioncreateTransition($name,$froms,$tos)
85+
{
86+
$this->add(newTransition($name,$froms,$tos));
87+
88+
}
89+
90+
privatefunctionadd(Transition$newTransition) {
91+
foreach ($this->transitionsas$transition) {
92+
if ($newTransition ==$transition) {
93+
thrownewInvalidArgumentException(sprintf('The transition named "%s" has already been added.',$name));
94+
}
95+
}
96+
$this->transitions[] =$newTransition;
97+
}
98+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp