mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-10 05:45:50 +00:00
Add #[YieldReady] to allow extensions to tell when they're ready for yielding
This commit is contained in:
+10
-13
@@ -55,8 +55,6 @@ class ModuleTest extends NodeTestCase
|
||||
$macros = new Node();
|
||||
$traits = new Node();
|
||||
$source = new Source('{{ foo }}', 'foo.twig');
|
||||
$parentTemplate = $this->getEnvironment()->useYield() ? 'YieldingTemplate' : 'Template';
|
||||
$displayStmt = $this->getEchoOrYield();
|
||||
|
||||
$node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source);
|
||||
$tests[] = [$node, <<<EOF
|
||||
@@ -73,10 +71,10 @@ use Twig\Sandbox\SecurityNotAllowedTagError;
|
||||
use Twig\Sandbox\SecurityNotAllowedFilterError;
|
||||
use Twig\Sandbox\SecurityNotAllowedFunctionError;
|
||||
use Twig\Source;
|
||||
use Twig\\{$parentTemplate};
|
||||
use Twig\Template;
|
||||
|
||||
/* foo.twig */
|
||||
class __TwigTemplate_%x extends $parentTemplate
|
||||
class __TwigTemplate_%x extends Template
|
||||
{
|
||||
private \$source;
|
||||
private \$macros = [];
|
||||
@@ -97,7 +95,8 @@ class __TwigTemplate_%x extends $parentTemplate
|
||||
{
|
||||
\$macros = \$this->macros;
|
||||
// line 1
|
||||
$displayStmt "foo";
|
||||
yield "foo";
|
||||
return; yield '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +127,6 @@ EOF
|
||||
|
||||
$body = new Node([$import]);
|
||||
$extends = new ConstantExpression('layout.twig', 1);
|
||||
$parentTemplate = $this->getEnvironment()->useYield() ? 'YieldingTemplate' : 'Template';
|
||||
|
||||
$node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source);
|
||||
$tests[] = [$node, <<<EOF
|
||||
@@ -145,10 +143,10 @@ use Twig\Sandbox\SecurityNotAllowedTagError;
|
||||
use Twig\Sandbox\SecurityNotAllowedFilterError;
|
||||
use Twig\Sandbox\SecurityNotAllowedFunctionError;
|
||||
use Twig\Source;
|
||||
use Twig\\{$parentTemplate};
|
||||
use Twig\Template;
|
||||
|
||||
/* foo.twig */
|
||||
class __TwigTemplate_%x extends $parentTemplate
|
||||
class __TwigTemplate_%x extends Template
|
||||
{
|
||||
private \$source;
|
||||
private \$macros = [];
|
||||
@@ -176,7 +174,7 @@ class __TwigTemplate_%x extends $parentTemplate
|
||||
\$macros["macro"] = \$this->macros["macro"] = \$this->loadTemplate("foo.twig", "foo.twig", 2)->unwrap();
|
||||
// line 1
|
||||
\$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1);
|
||||
{$this->getDisplayOrYield('$this->parent')}(\$context, array_merge(\$this->blocks, \$blocks));
|
||||
yield from \$this->parent->unwrap()->yield(\$context, array_merge(\$this->blocks, \$blocks));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +217,6 @@ EOF
|
||||
new ConstantExpression('foo', 2),
|
||||
2
|
||||
);
|
||||
$parentTemplate = $this->getEnvironment()->useYield() ? 'YieldingTemplate' : 'Template';
|
||||
|
||||
$twig = new Environment($this->createMock(LoaderInterface::class), ['debug' => true]);
|
||||
$node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source);
|
||||
@@ -237,10 +234,10 @@ use Twig\Sandbox\SecurityNotAllowedTagError;
|
||||
use Twig\Sandbox\SecurityNotAllowedFilterError;
|
||||
use Twig\Sandbox\SecurityNotAllowedFunctionError;
|
||||
use Twig\Source;
|
||||
use Twig\\{$parentTemplate};
|
||||
use Twig\Template;
|
||||
|
||||
/* foo.twig */
|
||||
class __TwigTemplate_%x extends $parentTemplate
|
||||
class __TwigTemplate_%x extends Template
|
||||
{
|
||||
private \$source;
|
||||
private \$macros = [];
|
||||
@@ -267,7 +264,7 @@ class __TwigTemplate_%x extends $parentTemplate
|
||||
// line 4
|
||||
\$context["foo"] = "foo";
|
||||
// line 2
|
||||
{$this->getDisplayOrYield('$this->getParent($context)')}(\$context, array_merge(\$this->blocks, \$blocks));
|
||||
yield from \$this->getParent(\$context)->unwrap()->yield(\$context, array_merge(\$this->blocks, \$blocks));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user