|
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: 01.09.16 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\Action\ExpressionLanguage; |
|
14
|
|
|
|
|
15
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Action\Registry; |
|
16
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\Action\Executor; |
|
17
|
|
|
use Gtt\Bundle\WorkflowExtensionsBundle\ExpressionLanguage\ContainerAwareExpressionLanguage; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
19
|
|
|
use Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Expression language allows to use actions inside expressions |
|
23
|
|
|
* |
|
24
|
|
|
* @author fduch <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class ActionExpressionLanguage extends ContainerAwareExpressionLanguage |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct( |
|
32
|
|
|
Registry $actionRegistry, |
|
33
|
|
|
Executor $actionExecutor, |
|
34
|
|
|
ContainerInterface $container, |
|
35
|
|
|
ParserCacheInterface $cache = null, |
|
36
|
|
|
array $providers = array()) |
|
37
|
|
|
{ |
|
38
|
|
|
parent::__construct($container, $cache, $providers); |
|
39
|
|
|
|
|
40
|
|
|
foreach ($actionRegistry as $actionName => $action) { |
|
41
|
|
|
$this->register( |
|
42
|
|
|
$actionName, |
|
43
|
|
|
function () use ($actionName, $actionExecutor) |
|
44
|
|
|
{ |
|
45
|
|
|
$rawArgs = func_get_args(); |
|
46
|
|
|
$compiledArgsArray = "array(". implode(", ", $rawArgs) . ")"; |
|
47
|
|
|
|
|
48
|
|
|
return sprintf( |
|
49
|
|
|
'$container->get("gtt.workflow.action.executor")->execute($workflowContext, "%s", %s)', |
|
50
|
|
|
$actionName, |
|
51
|
|
|
$compiledArgsArray |
|
52
|
|
|
); |
|
53
|
|
|
}, |
|
54
|
|
|
function () use ($actionName, $actionExecutor) |
|
55
|
|
|
{ |
|
56
|
|
|
$args = func_get_args(); |
|
57
|
|
|
$variables = array_shift($args); |
|
58
|
|
|
|
|
59
|
|
|
return $actionExecutor->execute($variables['workflowContext'], $actionName, $args); |
|
60
|
|
|
} |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|