FeatureFlagCallTokenParser example


        $_SERVER['TEST_TWIG'] = false;

        $deprecationMessage = null;
        set_error_handler(function D$errno$errstr) use (&$deprecationMessage) {
            $deprecationMessage = $errstr;

            return true;
        });

        $twig = new Environment(new ArrayLoader(['test.twig' => $twigCode]));
        $twig->addTokenParser(new FeatureFlagCallTokenParser());
        $twig->render('test.twig', [
            'foo' => new TestService(),
        ]);

        restore_error_handler();

        if ($shouldThrow) {
            static::assertNotNull($deprecationMessage);
        } else {
            static::assertNull($deprecationMessage);
        }

        
use Twig\TwigFunction;

#[Package('core')] class FeatureFlagExtension extends AbstractExtension
{
    /** * @return FeatureFlagCallTokenParser[] */
    public function getTokenParsers()
    {
        return [
            new FeatureFlagCallTokenParser(),
        ];
    }

    /** * @return TwigFunction[] */
    public function getFunctions(): array
    {
        return [
            new TwigFunction('feature', $this->feature(...)),
            new TwigFunction('getAllFeatures', $this->getAll(...)),
        ];
Home | Imprint | This part of the site doesn't use cookies.