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

Breadcrumb

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

function ExtensionSet::initExtension

1 call to ExtensionSet::initExtension()
ExtensionSet::initExtensions in vendor/twig/twig/src/ExtensionSet.php

File

vendor/twig/twig/src/ExtensionSet.php, line 432

Class

ExtensionSet
@author Fabien Potencier <fabien@symfony.com>

Namespace

Twig

Code

private function initExtension(ExtensionInterface $extension) : void {
    // filters
    foreach ($extension->getFilters() as $filter) {
        $this->filters[$name = $filter->getName()] = $filter;
        if (str_contains($name, '*')) {
            $this->dynamicFilters['#^' . str_replace('\\*', '(.*?)', preg_quote($name, '#')) . '$#'] = $filter;
        }
    }
    // functions
    foreach ($extension->getFunctions() as $function) {
        $this->functions[$name = $function->getName()] = $function;
        if (str_contains($name, '*')) {
            $this->dynamicFunctions['#^' . str_replace('\\*', '(.*?)', preg_quote($name, '#')) . '$#'] = $function;
        }
    }
    // tests
    foreach ($extension->getTests() as $test) {
        $this->tests[$name = $test->getName()] = $test;
        if (str_contains($name, '*')) {
            $this->dynamicTests['#^' . str_replace('\\*', '(.*?)', preg_quote($name, '#')) . '$#'] = $test;
        }
    }
    // token parsers
    foreach ($extension->getTokenParsers() as $parser) {
        if (!$parser instanceof TokenParserInterface) {
            throw new \LogicException('getTokenParsers() must return an array of \\Twig\\TokenParser\\TokenParserInterface.');
        }
        $this->parsers[$parser->getTag()] = $parser;
    }
    // node visitors
    foreach ($extension->getNodeVisitors() as $visitor) {
        $this->visitors[] = $visitor;
    }
    // operators
    if ($operators = $extension->getOperators()) {
        if (!\is_array($operators)) {
            throw new \InvalidArgumentException(\sprintf('"%s::getOperators()" must return an array with operators, got "%s".', \get_class($extension), get_debug_type($operators) . (\is_resource($operators) ? '' : '#' . $operators)));
        }
        if (2 !== \count($operators)) {
            throw new \InvalidArgumentException(\sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', \get_class($extension), \count($operators)));
        }
        $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]);
        $this->binaryOperators = array_merge($this->binaryOperators, $operators[1]);
    }
}
RSS feed
Powered by Drupal