NodeExtension example

$loader,
            $this->cacheDir,
            new NamespaceHierarchyBuilder([
                new BundleHierarchyBuilder(
                    $kernel,
                    $this->getContainer()->get(Connection::class)
                ),
            ]),
            $scopeDetector,
        );

        $twig->addExtension(new NodeExtension($templateFinder$scopeDetector));
        $twig->getExtension(NodeExtension::class)->getFinder();

        return $twig;
    }
}

/** * @internal */
class TestController extends StorefrontController
{
    
$loader,
            $this->cacheDir,
            new NamespaceHierarchyBuilder([
                new BundleHierarchyBuilder(
                    $kernel,
                    $this->getContainer()->get(Connection::class)
                ),
            ]),
            $scopeDetector,
        );

        $twig->addExtension(new NodeExtension($templateFinder$scopeDetector));
        $twig->getExtension(NodeExtension::class)->getFinder();

        return [$twig$templateFinder];
    }
}
$templateFinder = new TemplateFinder(
            $twig,
            $loader,
            sys_get_temp_dir() . '/twig_test_' . microtime(true),
            new NamespaceHierarchyBuilder([
                $builder,
            ]),
            $scopeDetector,
        );

        $twig->addExtension(new NodeExtension($templateFinder$scopeDetector));
        $twig->getExtension(NodeExtension::class)->getFinder();

        $twig->addExtension(new IconCacheTwigFilter());
        $twig->addExtension(new IconExtension($templateFinder));

        return $twig;
    }
}

/** * @internal */
use Twig\TokenParser\TokenParserInterface;

/** * @internal * * @covers \Shopware\Core\Framework\Adapter\Twig\Extension\NodeExtension */
class NodeExtensionTest extends TestCase
{
    public function testGetTokenParsers(): void
    {
        $extension = new NodeExtension(
            $this->createMock(TemplateFinder::class),
            $this->createMock(TemplateScopeDetector::class),
        );
        static::assertCount(3, $extension->getTokenParsers());
        static::assertSame([
            ExtendsTokenParser::class,
            IncludeTokenParser::class,
            ReturnNodeTokenParser::class,
        ]array_map(fn (TokenParserInterface $parser) => $parser::class$extension->getTokenParsers()));
    }

    
private array $nodeTranslators = [];
    private array $combinationTranslators = [];
    private array $functionTranslators = [];
    private array $pseudoClassTranslators = [];
    private array $attributeMatchingTranslators = [];

    public function __construct(ParserInterface $parser = null)
    {
        $this->mainParser = $parser ?? new Parser();

        $this
            ->registerExtension(new Extension\NodeExtension())
            ->registerExtension(new Extension\CombinationExtension())
            ->registerExtension(new Extension\FunctionExtension())
            ->registerExtension(new Extension\PseudoClassExtension())
            ->registerExtension(new Extension\AttributeMatchingExtension())
        ;
    }

    public static function getXpathLiteral(string $element): string
    {
        if (!str_contains($element, "'")) {
            return "'".$element."'";
        }
$loader,
            $this->getContainer()->getParameter('kernel.cache_dir') . '/' . microtime(),
            new NamespaceHierarchyBuilder([
                new BundleHierarchyBuilder(
                    $kernel,
                    $this->getContainer()->get(Connection::class)
                ),
            ]),
            $scopeDetector,
        );

        $twig->addExtension(new NodeExtension($templateFinder$scopeDetector));
        $twig->getExtension(NodeExtension::class)->getFinder();

        return $twig;
    }
}
Home | Imprint | This part of the site doesn't use cookies.