|
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; |
|
15
|
|
|
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; |
|
16
|
|
|
|
|
17
|
|
|
class AuthorizationExpressionProvider implements ExpressionFunctionProviderInterface |
|
18
|
|
|
{ |
|
19
|
38 |
|
public function getFunctions() |
|
20
|
|
|
{ |
|
21
|
|
|
return [ |
|
22
|
|
|
new ExpressionFunction('hasRole', function () {}, function (array $variables, $role) { |
|
23
|
1 |
|
return $variables['container']->get('security.authorization_checker')->isGranted($role); |
|
24
|
38 |
|
}), |
|
25
|
|
|
|
|
26
|
|
|
new ExpressionFunction('hasAnyRole', function () {}, function (array $variables, array $roles) { |
|
27
|
1 |
|
foreach ($roles as $role) { |
|
28
|
1 |
|
if ($variables['container']->get('security.authorization_checker')->isGranted($role)) { |
|
29
|
1 |
|
return true; |
|
30
|
|
|
} |
|
31
|
1 |
|
} |
|
32
|
|
|
|
|
33
|
1 |
|
return false; |
|
34
|
38 |
|
}), |
|
35
|
|
|
|
|
36
|
|
|
new ExpressionFunction('isAnonymous', function () {}, function (array $variables) { |
|
37
|
1 |
|
return $variables['container']->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_ANONYMOUSLY'); |
|
38
|
38 |
|
}), |
|
39
|
|
|
|
|
40
|
|
|
new ExpressionFunction('isRememberMe', function () {}, function (array $variables) { |
|
41
|
1 |
|
return $variables['container']->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED'); |
|
42
|
38 |
|
}), |
|
43
|
|
|
|
|
44
|
|
|
new ExpressionFunction('isFullyAuthenticated', function () {}, function (array $variables) { |
|
45
|
1 |
|
return $variables['container']->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY'); |
|
46
|
38 |
|
}), |
|
47
|
|
|
|
|
48
|
|
|
new ExpressionFunction('isAuthenticated', function () {}, function (array $variables) { |
|
49
|
|
|
return |
|
50
|
1 |
|
$variables['container']->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED') |
|
51
|
1 |
|
|| $variables['container']->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY'); |
|
52
|
38 |
|
}), |
|
53
|
|
|
|
|
54
|
|
|
new ExpressionFunction('hasPermission', function () {}, function (array $variables, $object, $permission) { |
|
55
|
1 |
|
return $variables['container']->get('security.authorization_checker')->isGranted($permission, $object); |
|
56
|
38 |
|
}), |
|
57
|
|
|
|
|
58
|
38 |
|
new ExpressionFunction('hasAnyPermission', function () {}, function (array $variables, $object, array $permissions) { |
|
59
|
1 |
|
foreach ($permissions as $permission) { |
|
60
|
1 |
|
if ($variables['container']->get('security.authorization_checker')->isGranted($permission, $object)) { |
|
61
|
1 |
|
return true; |
|
62
|
|
|
} |
|
63
|
1 |
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
return false; |
|
66
|
38 |
|
}), |
|
67
|
38 |
|
]; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|