Completed
Push — master ( bf1cb5...e1f92d )
by Antoine
22s queued 11s
created

ExpressionLanguageProvider::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
namespace ApiPlatform\Core\Security\Core\Authorization;
15
16
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
17
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
18
19
/**
20
 * Registers API Platform's Expression Language functions.
21
 *
22
 * @author Yanick Witschi <[email protected]>
23
 */
24
final class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
25
{
26
    public function getFunctions(): array
27
    {
28
        return [
29
            new ExpressionFunction('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
}
37