|
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
|
|
|
* @date 19.07.16 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Gtt\Bundle\WorkflowExtensionsBundle\ExpressionLanguage; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ExpressionLanguage; |
|
16
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; |
|
17
|
|
|
use Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Extends DI Expression Language with container variable holds ContainerInterface implementation |
|
21
|
|
|
*/ |
|
22
|
|
|
class ContainerAwareExpressionLanguage extends ExpressionLanguage |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* DI ContainerInterface implementation |
|
26
|
|
|
* |
|
27
|
|
|
* @var ContainerInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
private $container; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* ContainerAwareExpressionLanguage constructor |
|
33
|
|
|
* |
|
34
|
|
|
* @param ContainerInterface $container DI Container |
|
35
|
|
|
* @param ParserCacheInterface $cache cache |
|
36
|
|
|
* @param ExpressionFunctionProviderInterface[] $providers providers list |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(ContainerInterface $container, ParserCacheInterface $cache = null, array $providers = array()) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->container = $container; |
|
41
|
|
|
parent::__construct($cache, $providers); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Compile an expression with ContainerInterface context |
|
46
|
|
|
* |
|
47
|
|
|
* {@inheritdoc} |
|
48
|
|
|
*/ |
|
49
|
|
|
public function compile($expression, $names = array()) |
|
50
|
|
|
{ |
|
51
|
|
|
return parent::compile($expression, array_unique(array_merge($names, ["container"]))); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Evaluate an expression with ContainerInterface context |
|
56
|
|
|
* |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function evaluate($expression, $values = array()) |
|
60
|
|
|
{ |
|
61
|
|
|
return parent::evaluate($expression, $values + ["container" => $this->container]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Parse an expression with ContainerInterface context |
|
66
|
|
|
* |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function parse($expression, $names) |
|
70
|
|
|
{ |
|
71
|
|
|
return parent::parse($expression, array_unique(array_merge($names, ["container"]))); |
|
72
|
|
|
} |
|
73
|
|
|
} |