Completed
Push — master ( da004e...0c3139 )
by Antoine
16s
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
declare(strict_types=1);
13
/*
14
 * This file is part of the API Platform project.
15
 *
16
 * (c) Kévin Dunglas <[email protected]>
17
 *
18
 * For the full copyright and license information, please view the LICENSE
19
 * file that was distributed with this source code.
20
 */
21
22
namespace ApiPlatform\Core\Security;
23
24
use Symfony\Component\Security\Core\Authorization\ExpressionLanguage as BaseExpressionLanguage;
25
26
/**
27
 * Adds some function to the default Symfony Security ExpressionLanguage.
28
 *
29
 * @author Fabien Potencier <[email protected]>
30
 * @copyright Fabien Potencier <[email protected]>
31
 *
32
 * @see https://github.com/sensiolabs/SensioFrameworkExtraBundle/blob/master/Security/ExpressionLanguage.php
33
 */
34
class ExpressionLanguage extends BaseExpressionLanguage
35
{
36
    protected function registerFunctions()
37
    {
38
        parent::registerFunctions();
39
40
        $this->register('is_granted', function ($attributes, $object = 'null') {
41
            return sprintf('$auth_checker->isGranted(%s, %s)', $attributes, $object);
42
        }, function (array $variables, $attributes, $object = null) {
43
            return $variables['auth_checker']->isGranted($attributes, $object);
44
        });
45
    }
46
}
47