Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of the Symfony package.
5
 *
6
 * (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Component\Routing\Matcher;
13
 
14
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
15
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
16
use Symfony\Contracts\Service\ServiceProviderInterface;
17
 
18
/**
19
 * Exposes functions defined in the request context to route conditions.
20
 *
21
 * @author Ahmed TAILOULOUTE <ahmed.tailouloute@gmail.com>
22
 */
23
class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
24
{
25
    private ServiceProviderInterface $functions;
26
 
27
    public function __construct(ServiceProviderInterface $functions)
28
    {
29
        $this->functions = $functions;
30
    }
31
 
32
    public function getFunctions(): array
33
    {
34
        $functions = [];
35
 
36
        foreach ($this->functions->getProvidedServices() as $function => $type) {
37
            $functions[] = new ExpressionFunction(
38
                $function,
39
                static function (...$args) use ($function) {
40
                    return sprintf('($context->getParameter(\'_functions\')->get(%s)(%s))', var_export($function, true), implode(', ', $args));
41
                },
42
                function ($values, ...$args) use ($function) {
43
                    return $values['context']->getParameter('_functions')->get($function)(...$args);
44
                }
45
            );
46
        }
47
 
48
        return $functions;
49
    }
50
 
51
    public function get(string $function): callable
52
    {
53
        return $this->functions->get($function);
54
    }
55
}