1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Global Trading Technologies Ltd workflow-extension-bundle package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* (c) fduch <[email protected]> |
9
|
|
|
* |
10
|
|
|
* Date: 31.08.16 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\Action; |
14
|
|
|
|
15
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Action\Reference\ActionReferenceInterface; |
16
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Exception\ActionException; |
17
|
|
|
use IteratorAggregate; |
18
|
|
|
use ArrayIterator; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Workflow action registry |
22
|
|
|
* |
23
|
|
|
* @author fduch <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class Registry implements IteratorAggregate |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* List of workflow actions |
29
|
|
|
* |
30
|
|
|
* @var ActionReferenceInterface[] |
31
|
|
|
*/ |
32
|
|
|
private $actions = []; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Registry constructor. |
36
|
|
|
* |
37
|
|
|
* @param array $actions list of action names associated to action references |
38
|
|
|
*/ |
39
|
|
|
public function __construct(array $actions = []) |
40
|
|
|
{ |
41
|
|
|
foreach ($actions as $actionName => $actionReference) { |
42
|
|
|
$this->add($actionName, $actionReference); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Registers action by name in repository |
48
|
|
|
* |
49
|
|
|
* @param string $actionName action name |
50
|
|
|
* @param ActionReferenceInterface $action action reference |
51
|
|
|
*/ |
52
|
|
|
public function add($actionName, ActionReferenceInterface $action) |
53
|
|
|
{ |
54
|
|
|
if (array_key_exists($actionName, $this->actions)) { |
55
|
|
|
throw ActionException::actionAlreadyRegistered($actionName); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->actions[$actionName] = $action; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns ActionInterface by name |
63
|
|
|
* |
64
|
|
|
* @param string $actionName action name |
65
|
|
|
* |
66
|
|
|
* @return ActionReferenceInterface |
67
|
|
|
*/ |
68
|
|
|
public function get($actionName) |
69
|
|
|
{ |
70
|
|
|
if (!array_key_exists($actionName, $this->actions)) { |
71
|
|
|
throw ActionException::actionNotFound($actionName); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this->actions[$actionName]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getIterator() |
78
|
|
|
{ |
79
|
|
|
return new ArrayIterator($this->actions); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|