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

Breadcrumb

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

function ExpressionLanguageProvider::getFunctions

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

File

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

Class

ExpressionLanguageProvider
Define some ExpressionLanguage functions.

Namespace

Symfony\Component\DependencyInjection

Code

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)),
    ];
}
RSS feed
Powered by Drupal