Skip to content

Commit

Permalink
minor #4446 Improve YieldReady support docs (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Improve YieldReady support docs

Refs #4428

Commits
-------

9d9c9d8 Improve YieldReady support docs
  • Loading branch information
fabpot committed Nov 12, 2024
2 parents 0ca3815 + 9d9c9d8 commit c5d0d59
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions doc/deprecated.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ Nodes
Twig 3.15; use ``Twig\Node\Expression\Variable\AssignContextVariable``
instead.

* Node implementations that use ``echo`` or ``print`` should use ``yield``
instead; all Node implementations should use the
``#[\Twig\Attribute\YieldReady]`` attribute on their class once they've been
made ready for ``yield``; the ``use_yield`` Environment option can be turned
on when all nodes use the ``#[\Twig\Attribute\YieldReady]`` attribute.

Node Visitors
-------------

Expand Down
4 changes: 2 additions & 2 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function compile(Node $node, int $indentation = 0)
$node->compile($this);

if ($this->didUseEcho) {
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));
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));
}

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

if ($this->didUseEcho) {
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));
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));
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/NodeVisitor/YieldNotReadyNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function enterNode(Node $node, Environment $env): Node
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));
}

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);
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);
}

return $node;
Expand Down
6 changes: 3 additions & 3 deletions tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,11 @@ public function testLegacyEchoingNode()

if ($twig->useYield()) {
$this->expectException(SyntaxError::class);
$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".');
$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".');
} else {
$this->expectDeprecation(<<<'EOF'
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.
Since twig/twig 3.9: Using "echo" is deprecated, use "yield" instead in "Twig\Tests\EnvironmentTest_LegacyEchoingNode", then flag the class with #[YieldReady].
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.
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].
EOF
);
}
Expand Down

0 comments on commit c5d0d59

Please sign in to comment.