Skip to content

Commit c5d0d59

Browse files
committed
minor #4446 Improve YieldReady support docs (fabpot)
This PR was merged into the 3.x branch. Discussion ---------- Improve YieldReady support docs Refs #4428 Commits ------- 9d9c9d8 Improve YieldReady support docs
2 parents 0ca3815 + 9d9c9d8 commit c5d0d59

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

doc/deprecated.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ Nodes
183183
Twig 3.15; use ``Twig\Node\Expression\Variable\AssignContextVariable``
184184
instead.
185185

186+
* Node implementations that use ``echo`` or ``print`` should use ``yield``
187+
instead; all Node implementations should use the
188+
``#[\Twig\Attribute\YieldReady]`` attribute on their class once they've been
189+
made ready for ``yield``; the ``use_yield`` Environment option can be turned
190+
on when all nodes use the ``#[\Twig\Attribute\YieldReady]`` attribute.
191+
186192
Node Visitors
187193
-------------
188194

src/Compiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function compile(Node $node, int $indentation = 0)
7474
$node->compile($this);
7575

7676
if ($this->didUseEcho) {
77-
trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[YieldReady].', $this->didUseEcho, \get_class($node));
77+
trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[\Twig\Attribute\YieldReady].', $this->didUseEcho, \get_class($node));
7878
}
7979

8080
return $this;
@@ -99,7 +99,7 @@ public function subcompile(Node $node, bool $raw = true)
9999
$node->compile($this);
100100

101101
if ($this->didUseEcho) {
102-
trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[YieldReady].', $this->didUseEcho, \get_class($node));
102+
trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[\Twig\Attribute\YieldReady].', $this->didUseEcho, \get_class($node));
103103
}
104104

105105
return $this;

src/NodeVisitor/YieldNotReadyNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function enterNode(Node $node, Environment $env): Node
4141
throw new \LogicException(\sprintf('You cannot enable the "use_yield" option of Twig as node "%s" is not marked as ready for it; please make it ready and then flag it with the #[YieldReady] attribute.', $class));
4242
}
4343

44-
trigger_deprecation('twig/twig', '3.9', 'Twig node "%s" is not marked as ready for using "yield" instead of "echo"; please make it ready and then flag it with the #[YieldReady] attribute.', $class);
44+
trigger_deprecation('twig/twig', '3.9', 'Twig node "%s" is not marked as ready for using "yield" instead of "echo"; please make it ready and then flag it with the #[\Twig\Attribute\YieldReady] attribute.', $class);
4545
}
4646

4747
return $node;

tests/EnvironmentTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,11 @@ public function testLegacyEchoingNode()
445445

446446
if ($twig->useYield()) {
447447
$this->expectException(SyntaxError::class);
448-
$this->expectExceptionMessage('An exception has been thrown during the compilation of a template ("You cannot enable the "use_yield" option of Twig as node "Twig\Tests\EnvironmentTest_LegacyEchoingNode" is not marked as ready for it; please make it ready and then flag it with the #[YieldReady] attribute.") in "echo_bar".');
448+
$this->expectExceptionMessage('An exception has been thrown during the compilation of a template ("You cannot enable the "use_yield" option of Twig as node "Twig\Tests\EnvironmentTest_LegacyEchoingNode" is not marked as ready for it; please make it ready and then flag it with the #[\Twig\Attribute\YieldReady] attribute.") in "echo_bar".');
449449
} else {
450450
$this->expectDeprecation(<<<'EOF'
451-
Since twig/twig 3.9: Twig node "Twig\Tests\EnvironmentTest_LegacyEchoingNode" is not marked as ready for using "yield" instead of "echo"; please make it ready and then flag it with the #[YieldReady] attribute.
452-
Since twig/twig 3.9: Using "echo" is deprecated, use "yield" instead in "Twig\Tests\EnvironmentTest_LegacyEchoingNode", then flag the class with #[YieldReady].
451+
Since twig/twig 3.9: Twig node "Twig\Tests\EnvironmentTest_LegacyEchoingNode" is not marked as ready for using "yield" instead of "echo"; please make it ready and then flag it with the #[\Twig\Attribute\YieldReady] attribute.
452+
Since twig/twig 3.9: Using "echo" is deprecated, use "yield" instead in "Twig\Tests\EnvironmentTest_LegacyEchoingNode", then flag the class with #[\Twig\Attribute\YieldReady].
453453
EOF
454454
);
455455
}

0 commit comments

Comments
 (0)