Remove usage of ob_* functions in favor of yielding

This commit is contained in:
Fabien Potencier
2024-01-25 13:09:52 +01:00
parent 594c548b92
commit 3b6cbf98d8
30 changed files with 657 additions and 78 deletions
+11 -8
View File
@@ -55,6 +55,7 @@ class ModuleTest extends NodeTestCase
$macros = new Node();
$traits = new Node();
$source = new Source('{{ foo }}', 'foo.twig');
$parentTemplate = $this->getEnvironment()->useYield() ? 'YieldingTemplate' : 'Template';
$node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source);
$tests[] = [$node, <<<EOF
@@ -71,10 +72,10 @@ use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
use Twig\\{$parentTemplate};
/* foo.twig */
class __TwigTemplate_%x extends Template
class __TwigTemplate_%x extends $parentTemplate
{
private \$source;
private \$macros = [];
@@ -126,6 +127,7 @@ 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
@@ -142,10 +144,10 @@ use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
use Twig\\{$parentTemplate};
/* foo.twig */
class __TwigTemplate_%x extends Template
class __TwigTemplate_%x extends $parentTemplate
{
private \$source;
private \$macros = [];
@@ -173,7 +175,7 @@ class __TwigTemplate_%x extends Template
\$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->parent->display(\$context, array_merge(\$this->blocks, \$blocks));
{$this->getDisplayOrYield('$this->parent')}(\$context, array_merge(\$this->blocks, \$blocks));
}
/**
@@ -216,6 +218,7 @@ 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);
@@ -233,10 +236,10 @@ use Twig\Sandbox\SecurityNotAllowedTagError;
use Twig\Sandbox\SecurityNotAllowedFilterError;
use Twig\Sandbox\SecurityNotAllowedFunctionError;
use Twig\Source;
use Twig\Template;
use Twig\\{$parentTemplate};
/* foo.twig */
class __TwigTemplate_%x extends Template
class __TwigTemplate_%x extends $parentTemplate
{
private \$source;
private \$macros = [];
@@ -263,7 +266,7 @@ class __TwigTemplate_%x extends Template
// line 4
\$context["foo"] = "foo";
// line 2
\$this->getParent(\$context)->display(\$context, array_merge(\$this->blocks, \$blocks));
{$this->getDisplayOrYield('$this->getParent($context)')}(\$context, array_merge(\$this->blocks, \$blocks));
}
/**