1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
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
|
|
|
namespace Overblog\GraphQLBundle\ExpressionLanguage; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareTrait; |
15
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionLanguage as BaseExpressionLanguage; |
16
|
|
|
use Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface; |
17
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
18
|
|
|
|
19
|
|
|
class ExpressionLanguage extends BaseExpressionLanguage |
20
|
|
|
{ |
21
|
|
|
use ContainerAwareTrait; |
22
|
|
|
|
23
|
38 |
|
public function __construct(ParserCacheInterface $parser = null, array $providers = []) |
24
|
|
|
{ |
25
|
|
|
// prepend the default provider to let users override it easily |
26
|
38 |
|
array_unshift($providers, new ConfigExpressionProvider()); |
27
|
38 |
|
array_unshift($providers, new AuthorizationExpressionProvider()); |
28
|
|
|
|
29
|
38 |
|
parent::__construct($parser, $providers); |
30
|
38 |
|
} |
31
|
|
|
|
32
|
29 |
|
public function evaluate($expression, $values = []) |
33
|
|
|
{ |
34
|
29 |
|
$this->addValues($values); |
35
|
|
|
|
36
|
29 |
|
return parent::evaluate($expression, $values); |
37
|
|
|
} |
38
|
|
|
|
39
|
29 |
|
private function addValues(&$values) |
40
|
1 |
|
{ |
41
|
29 |
|
$values['container'] = $this->container; |
42
|
|
|
|
43
|
29 |
|
if ($this->container->has('request_stack')) { |
44
|
14 |
|
$values['request'] = $this->container->get('request_stack')->getCurrentRequest(); |
45
|
14 |
|
} |
46
|
|
|
|
47
|
29 |
|
if ($this->container->has('security.token_storage')) { |
48
|
|
|
$values['token'] = $this->container->get('security.token_storage')->getToken(); |
49
|
|
|
if ($values['token'] instanceof TokenInterface) { |
50
|
|
|
$values['user'] = $values['token']->getUser(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
29 |
|
} |
54
|
|
|
} |
55
|
|
|
|