Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExpressionLanguageProvider.php

class ExpressionLanguageProvider

Same name in this branch
  1. 11.1.x vendor/symfony/validator/Constraints/ExpressionLanguageProvider.php \Symfony\Component\Validator\Constraints\ExpressionLanguageProvider
  2. 11.1.x vendor/symfony/routing/Matcher/ExpressionLanguageProvider.php \Symfony\Component\Routing\Matcher\ExpressionLanguageProvider

Define some ExpressionLanguage functions.

To get a service, use service('request'). To get a parameter, use parameter('kernel.debug'). To get an env variable, use env('SOME_VARIABLE').

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Symfony\Component\DependencyInjection\ExpressionLanguageProvider implements \Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface

Expanded class hierarchy of ExpressionLanguageProvider

File

vendor/symfony/dependency-injection/ExpressionLanguageProvider.php, line 27

Namespace

Symfony\Component\DependencyInjection
View source
class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface {
    private ?\Closure $serviceCompiler;
    public function __construct(?callable $serviceCompiler = null, ?\Closure $getEnv = null) {
        $this->serviceCompiler = null === $serviceCompiler ? null : $serviceCompiler(...);
    }
    public function getFunctions() : array {
        return [
            new ExpressionFunction('service', $this->serviceCompiler ?? fn($arg) => \sprintf('$container->get(%s)', $arg), fn(array $variables, $value) => $variables['container']->get($value)),
            new ExpressionFunction('parameter', fn($arg) => \sprintf('$container->getParameter(%s)', $arg), fn(array $variables, $value) => $variables['container']->getParameter($value)),
            new ExpressionFunction('env', fn($arg) => \sprintf('$container->getEnv(%s)', $arg), function (array $variables, $value) {
                if (!$this->getEnv) {
                    throw new LogicException('You need to pass a getEnv closure to the expression language provider to use the "env" function.');
                }
                return ($this->getEnv)($value);
            }),
            new ExpressionFunction('arg', fn($arg) => \sprintf('$args?->get(%s)', $arg), fn(array $variables, $value) => $variables['args']?->get($value)),
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary
ExpressionLanguageProvider::$serviceCompiler private property
ExpressionLanguageProvider::getFunctions public function
ExpressionLanguageProvider::__construct public function
RSS feed
Powered by Drupal