Completed
Pull Request — master (#1216)
by Kévin
02:49
created

ExpressionLanguage   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 13
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A registerFunctions() 0 10 1
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
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 ApiPlatform\Core\Security;
13
14
use Symfony\Component\Security\Core\Authorization\ExpressionLanguage as BaseExpressionLanguage;
15
16
/**
17
 * Adds some function to the default Symfony Security ExpressionLanguage.
18
 *
19
 * @author Fabien Potencier <[email protected]>
20
 * @copyright Fabien Potencier <[email protected]>
21
 * @see https://github.com/sensiolabs/SensioFrameworkExtraBundle/blob/master/Security/ExpressionLanguage.php
22
 */
23
class ExpressionLanguage extends BaseExpressionLanguage
24
{
25
    protected function registerFunctions()
26
    {
27
        parent::registerFunctions();
28
29
        $this->register('is_granted', function ($attributes, $object = 'null') {
30
            return sprintf('$auth_checker->isGranted(%s, %s)', $attributes, $object);
31
        }, function (array $variables, $attributes, $object = null) {
32
            return $variables['auth_checker']->isGranted($attributes, $object);
33
        });
34
    }
35
}
36