This commit is contained in:
2021-12-06 13:54:48 +01:00
parent cfd6acbbb8
commit f5cb936c97
111 changed files with 2189 additions and 858 deletions

View File

@@ -0,0 +1,49 @@
<?php
/**
* This file is part of the rybakit/twig-deferred-extension package.
*
* (c) Eugene Leonovich <gen.work@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Twig\DeferredExtension;
use Twig\Environment;
use Twig\Node\ModuleNode;
use Twig\Node\Node;
use Twig\NodeVisitor\NodeVisitorInterface;
final class DeferredNodeVisitor implements NodeVisitorInterface
{
private $hasDeferred = false;
public function enterNode(Node $node, Environment $env) : Node
{
if (!$this->hasDeferred && $node instanceof DeferredBlockNode) {
$this->hasDeferred = true;
}
return $node;
}
public function leaveNode(Node $node, Environment $env) : ?Node
{
if ($this->hasDeferred && $node instanceof ModuleNode) {
$node->setNode('constructor_end', new Node([new DeferredExtensionNode(), $node->getNode('constructor_end')]));
$node->setNode('display_end', new Node([new DeferredNode(), $node->getNode('display_end')]));
$this->hasDeferred = false;
}
return $node;
}
public function getPriority() : int
{
return 0;
}
}