Skip to content

Commit a39d080

Browse files
author
Jeremiah VALERIE
committed
Refactor ExpressionLanguage functions
Now the ExpressionFunction no more requires unuse evaluation function.
1 parent dd35bf4 commit a39d080

File tree

3 files changed

+24
-50
lines changed

3 files changed

+24
-50
lines changed

ExpressionLanguage/AuthorizationExpressionProvider.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Overblog\GraphQLBundle\ExpressionLanguage;
1313

14-
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
1514
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
1615

1716
class AuthorizationExpressionProvider implements ExpressionFunctionProviderInterface
@@ -23,8 +22,6 @@ public function getFunctions()
2322
'hasRole',
2423
function ($role) {
2524
return sprintf('$container->get(\'security.authorization_checker\')->isGranted(%s)', $role);
26-
},
27-
function () {
2825
}
2926
),
3027

@@ -34,26 +31,20 @@ function ($roles) {
3431
$code = sprintf('array_reduce(%s, function ($isGranted, $role) use ($container) { return $isGranted || $container->get(\'security.authorization_checker\')->isGranted($role); }, false)', $roles);
3532

3633
return $code;
37-
},
38-
function () {
3934
}
4035
),
4136

4237
new ExpressionFunction(
4338
'isAnonymous',
4439
function () {
4540
return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_ANONYMOUSLY\')';
46-
},
47-
function () {
4841
}
4942
),
5043

5144
new ExpressionFunction(
5245
'isRememberMe',
5346
function () {
5447
return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\')';
55-
},
56-
function () {
5748
}
5849
),
5950

@@ -70,8 +61,6 @@ function () {
7061
'isAuthenticated',
7162
function () {
7263
return '$container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_REMEMBERED\') || $container->get(\'security.authorization_checker\')->isGranted(\'IS_AUTHENTICATED_FULLY\')';
73-
},
74-
function () {
7564
}
7665
),
7766

@@ -81,8 +70,6 @@ function ($object, $permission) {
8170
$code = sprintf('$container->get(\'security.authorization_checker\')->isGranted(%s, %s)', $permission, $object);
8271

8372
return $code;
84-
},
85-
function () {
8673
}
8774
),
8875

@@ -92,8 +79,6 @@ function ($object, $permissions) {
9279
$code = sprintf('array_reduce(%s, function ($isGranted, $permission) use ($container, $object) { return $isGranted || $container->get(\'security.authorization_checker\')->isGranted($permission, %s); }, false)', $permissions, $object);
9380

9481
return $code;
95-
},
96-
function () {
9782
}
9883
),
9984
];

ExpressionLanguage/ConfigExpressionProvider.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Overblog\GraphQLBundle\ExpressionLanguage;
1313

1414
use Overblog\GraphQLBundle\Generator\TypeGenerator;
15-
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
1615
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
1716

1817
class ConfigExpressionProvider implements ExpressionFunctionProviderInterface
@@ -24,35 +23,27 @@ public function getFunctions()
2423
'service',
2524
function ($value) {
2625
return sprintf('$container->get(%s)', $value);
27-
},
28-
function () {
2926
}
3027
),
3128

3229
new ExpressionFunction(
3330
'parameter',
3431
function ($value) {
3532
return sprintf('$container->getParameter(%s)', $value);
36-
},
37-
function () {
3833
}
3934
),
4035

4136
new ExpressionFunction(
4237
'isTypeOf',
4338
function ($className) {
4439
return sprintf('($className = %s) && $value instanceof $className', $className);
45-
},
46-
function () {
4740
}
4841
),
4942

5043
new ExpressionFunction(
5144
'resolver',
5245
function ($alias, $args = '[]') {
5346
return sprintf('$container->get(\'overblog_graphql.resolver_resolver\')->resolve([%s, %s])', $alias, $args);
54-
},
55-
function () {
5647
}
5748
),
5849

@@ -63,20 +54,6 @@ function ($mutateAndGetPayload) {
6354
$code .= 'return '.$mutateAndGetPayload.'; }';
6455

6556
return $code;
66-
},
67-
function () {
68-
}
69-
),
70-
71-
new ExpressionFunction(
72-
'mutateAndGetPayloadCallback',
73-
function ($mutateAndGetPayload) {
74-
$code = 'function ($value) use ('.TypeGenerator::USE_FOR_CLOSURES.', $args, $info) { ';
75-
$code .= 'return '.$mutateAndGetPayload.'; }';
76-
77-
return $code;
78-
},
79-
function () {
8057
}
8158
),
8259

@@ -87,8 +64,6 @@ function ($idFetcher) {
8764
$code .= 'return '.$idFetcher.'; }';
8865

8966
return $code;
90-
},
91-
function () {
9267
}
9368
),
9469

@@ -99,17 +74,13 @@ function ($resolveSingleInput) {
9974
$code .= 'return '.$resolveSingleInput.'; }';
10075

10176
return $code;
102-
},
103-
function () {
10477
}
10578
),
10679

10780
new ExpressionFunction(
10881
'mutation',
10982
function ($alias, $args = '[]') {
11083
return sprintf('$container->get(\'overblog_graphql.mutation_resolver\')->resolve([%s, %s])', $alias, $args);
111-
},
112-
function () {
11384
}
11485
),
11586

@@ -123,8 +94,6 @@ function ($id, $typeName = null) {
12394
sprintf($typeNameEmpty ? '$info->parentType->name' : '%s', $typeName),
12495
$id
12596
);
126-
},
127-
function () {
12897
}
12998
),
13099

@@ -135,17 +104,13 @@ function ($globalId) {
135104
'\\Overblog\\GraphQLBundle\\Relay\\Node\\GlobalId::fromGlobalId(%s)',
136105
$globalId
137106
);
138-
},
139-
function () {
140107
}
141108
),
142109

143110
new ExpressionFunction(
144111
'newObject',
145112
function ($className, $args = '[]') {
146113
return sprintf('(new \ReflectionClass(%s))->newInstanceArgs(%s)', $className, $args);
147-
},
148-
function () {
149114
}
150115
),
151116
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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\ExpressionLanguage\ExpressionFunction as BaseExpressionFunction;
15+
16+
class ExpressionFunction extends BaseExpressionFunction
17+
{
18+
public function __construct($name, callable $compiler)
19+
{
20+
parent::__construct($name, $compiler, function () {
21+
throw new \RuntimeException('No need evaluator.');
22+
});
23+
}
24+
}

0 commit comments

Comments
 (0)