Compiler example

/** * @internal */
#[Package('core')] class TwigEnvironment extends Environment
{
    private ?Compiler $compiler = null;

    public function compile(Node $node): string
    {
        if ($this->compiler === null) {
            $this->compiler = new Compiler($this);
        }

        $source = $this->compiler->compile($node)->getSource();

        $source = str_replace('twig_get_attribute(', 'sw_get_attribute(', $source);
        $source = str_replace('twig_escape_filter(', 'sw_escape_filter(', $source);
        $source = str_replace('use Twig\Environment;', "use Twig\Environment;\nuse function Shopware\Core\Framework\Adapter\Twig\sw_get_attribute;\nuse function Shopware\Core\Framework\Adapter\Twig\sw_escape_filter;", $source);

        return $source;
    }
}
/** * @var array<string, mixed>|null */
    private readonly ?array $cacheOptions;

    /** * @param array<string, mixed>|null $cacheOptions */
    public function __construct(?array $cacheOptions = null)
    {
        $this->compiler = new Compiler($cacheOptions);
        $this->cacheOptions = $cacheOptions;
    }

    public function reset(): void
    {
        $this->compiler = new Compiler($this->cacheOptions);
    }

    public function compileString(AbstractCompilerConfiguration $config, string $scss, ?string $path = null): string
    {
        $outputStyle = $config->getValue('outputStyle');

        
/** * @internal * * @covers \Shopware\Core\Framework\Adapter\Twig\Node\FeatureCallSilentToken */
class FeatureCallSilentTokenTest extends TestCase
{
    public function testCompile(): void
    {
        $token = new FeatureCallSilentToken('v6.5.0.0', new TextNode('test', 1), 1, 'sw_feature');

        $compiler = new Compiler(new Environment(new ArrayLoader()));

        $compiler->compile($token);

        $code = <<<'PHP' // line 1 \Shopware\Core\Framework\Feature::callSilentIfInactive('v6.5.0.0', function () use(&$context) { echo "test"; }); PHP;

        static::assertSame($code$compiler->getSource());
    }
}
Home | Imprint | This part of the site doesn't use cookies.