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 Overblog\GraphQLBundle\Relay\Node\GlobalId; |
15
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionFunction; |
16
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; |
17
|
|
|
|
18
|
|
|
class ConfigExpressionProvider implements ExpressionFunctionProviderInterface |
19
|
|
|
{ |
20
|
38 |
|
public function getFunctions() |
21
|
|
|
{ |
22
|
|
|
return [ |
23
|
|
|
new ExpressionFunction('service', function () {}, function (array $variables, $value) { |
24
|
3 |
|
return $variables['container']->get($value); |
25
|
38 |
|
}), |
26
|
|
|
|
27
|
|
|
new ExpressionFunction('parameter', function () {}, function (array $variables, $value) { |
28
|
1 |
|
return $variables['container']->getParameter($value); |
29
|
38 |
|
}), |
30
|
|
|
|
31
|
|
|
new ExpressionFunction('isTypeOf', function () {}, function (array $variables, $className) { |
32
|
1 |
|
return $variables['value'] instanceof $className; |
33
|
38 |
|
}), |
34
|
|
|
|
35
|
|
|
new ExpressionFunction('resolver', function () {}, function (array $variables, $alias, array $args = []) { |
36
|
11 |
|
return $variables['container']->get('overblog_graphql.resolver_resolver')->resolve([$alias, $args]); |
37
|
38 |
|
}), |
38
|
|
|
|
39
|
|
|
new ExpressionFunction('mutation', function () {}, function (array $variables, $alias, array $args = []) { |
40
|
1 |
|
return $variables['container']->get('overblog_graphql.mutation_resolver')->resolve([$alias, $args]); |
41
|
38 |
|
}), |
42
|
|
|
|
43
|
|
|
new ExpressionFunction('globalId', function () {}, function (array $variables, $id, $typeName = null) { |
44
|
1 |
|
$type = !empty($typeName) ? $typeName : $variables['info']->parentType->name; |
45
|
|
|
|
46
|
1 |
|
return GlobalId::toGlobalId($type, $id); |
47
|
38 |
|
}), |
48
|
|
|
|
49
|
|
|
new ExpressionFunction('fromGlobalId', function () {}, function (array $variables, $globalId) { |
50
|
1 |
|
return GlobalId::fromGlobalId($globalId); |
51
|
38 |
|
}), |
52
|
|
|
|
53
|
38 |
|
new ExpressionFunction('newObject', function () {}, function (array $variables, $className, array $args = []) { |
54
|
1 |
|
return (new \ReflectionClass($className))->newInstanceArgs($args); |
55
|
38 |
|
}), |
56
|
38 |
|
]; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|