getFunctions example


        static::assertSame($finder$extension->getFinder());
    }

    public function testEmptyExtensions(): void
    {
        $extension = new NodeExtension(
            $this->createMock(TemplateFinder::class),
            $this->createMock(TemplateScopeDetector::class),
        );

        static::assertEmpty($extension->getFunctions());
        static::assertEmpty($extension->getFilters());
        static::assertEmpty($extension->getNodeVisitors());
        static::assertEmpty($extension->getOperators());
        static::assertEmpty($extension->getTests());
    }
}

    public function getFunctions(): array
    {
        return $this->extensionSet->getFunctions();
    }

    /** * Registers a Global. * * New globals can be added before compiling or rendering a template; * but after, you can only update existing globals. * * @param mixed $value The global value */
    public function addGlobal(string $name$value)
    {
trigger_error($message, \E_USER_DEPRECATED);
        }

        return $test->getNodeClass();
    }

    private function getFunctionNodeClass(string $name, int $line): string
    {
        if (!$function = $this->env->getFunction($name)) {
            $e = new SyntaxError(sprintf('Unknown "%s" function.', $name)$line$this->parser->getStream()->getSourceContext());
            $e->addSuggestions($namearray_keys($this->env->getFunctions()));

            throw $e;
        }

        if ($function->isDeprecated()) {
            $message = sprintf('Twig Function "%s" is deprecated', $function->getName());
            if ($function->getDeprecatedVersion()) {
                $message .= sprintf(' since version %s', $function->getDeprecatedVersion());
            }
            if ($function->getAlternative()) {
                $message .= sprintf('. Use "%s" instead', $function->getAlternative());
            }

    public function addFunction(ExpressionFunction $function)
    {
        $this->register($function->getName()$function->getCompiler()$function->getEvaluator());
    }

    /** * @return void */
    public function registerProvider(ExpressionFunctionProviderInterface $provider)
    {
        foreach ($provider->getFunctions() as $function) {
            $this->addFunction($function);
        }
    }

    /** * @return void */
    protected function registerFunctions()
    {
        $this->addFunction(ExpressionFunction::fromPhp('constant'));

        
        $this->initialized = true;
    }

    private function initExtension(ExtensionInterface $extension): void
    {
        // filters         foreach ($extension->getFilters() as $filter) {
            $this->filters[$filter->getName()] = $filter;
        }

        // functions         foreach ($extension->getFunctions() as $function) {
            $this->functions[$function->getName()] = $function;
        }

        // tests         foreach ($extension->getTests() as $test) {
            $this->tests[$test->getName()] = $test;
        }

        // token parsers         foreach ($extension->getTokenParsers() as $parser) {
            if (!$parser instanceof TokenParserInterface) {
                
Home | Imprint | This part of the site doesn't use cookies.