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: 23.09.16 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\Action; |
14
|
|
|
|
15
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Action\Reference\ActionReferenceInterface; |
16
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\WorkflowContext; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Action executor |
22
|
|
|
* |
23
|
|
|
* @author fduch <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class Executor |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Action registry |
29
|
|
|
* |
30
|
|
|
* @var Registry |
31
|
|
|
*/ |
32
|
|
|
private $registry; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Container DI |
36
|
|
|
* |
37
|
|
|
* @var ContainerInterface |
38
|
|
|
*/ |
39
|
|
|
private $container; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Executor constructor. |
43
|
|
|
* |
44
|
|
|
* @param Registry $registry action registry |
45
|
|
|
* @param ContainerInterface $container container DI |
46
|
|
|
*/ |
47
|
|
|
public function __construct(Registry $registry, ContainerInterface $container) |
48
|
|
|
{ |
49
|
|
|
$this->registry = $registry; |
50
|
|
|
$this->container = $container; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Executes action |
55
|
|
|
* |
56
|
|
|
* @param WorkflowContext $workflowContext workflow context |
57
|
|
|
* @param string $actionName action name |
58
|
|
|
* @param array $args action arguments |
59
|
|
|
* |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
|
|
public function execute(WorkflowContext $workflowContext, $actionName, array $args = []) |
63
|
|
|
{ |
64
|
|
|
$actionReference = $this->registry->get($actionName); |
65
|
|
|
|
66
|
|
|
if ($actionReference->getType() == ActionReferenceInterface::TYPE_WORKFLOW) { |
67
|
|
|
array_unshift($args, $workflowContext); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if ($actionReference instanceof ContainerAwareInterface) { |
71
|
|
|
// container should be injected to allow action to use service as an method owner |
72
|
|
|
$actionReference->setContainer($this->container); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $actionReference->invoke($args); |
76
|
|
|
} |
77
|
|
|
} |