-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
#[YieldReady]
to allow extensions to tell when they're ready fo…
…r yielding
- Loading branch information
1 parent
7f5958c
commit e707774
Showing
59 changed files
with
654 additions
and
760 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Twig\Attribute; | ||
|
||
/** | ||
* Marks nodes that are ready for using "yield" instead of "echo" or "print()" for rendering. | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
final class YieldReady | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Twig. | ||
* | ||
* (c) Fabien Potencier | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Twig\Extension; | ||
|
||
use Twig\NodeVisitor\YieldNotReadyNodeVisitor; | ||
|
||
/** | ||
* @internal to be removed in Twig 4 | ||
*/ | ||
final class YieldNotReadyExtension extends AbstractExtension | ||
{ | ||
private $useYield; | ||
|
||
public function __construct(bool $useYield) | ||
{ | ||
$this->useYield = $useYield; | ||
} | ||
|
||
public function getNodeVisitors(): array | ||
{ | ||
return [new YieldNotReadyNodeVisitor($this->useYield)]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace Twig\Node; | ||
|
||
use Twig\Attribute\YieldReady; | ||
use Twig\Compiler; | ||
|
||
/** | ||
|
@@ -24,6 +25,7 @@ | |
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
#[YieldReady] | ||
class AutoEscapeNode extends Node | ||
{ | ||
public function __construct($value, Node $body, int $lineno, string $tag = 'autoescape') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,15 @@ | |
|
||
namespace Twig\Node; | ||
|
||
use Twig\Attribute\YieldReady; | ||
use Twig\Compiler; | ||
|
||
/** | ||
* Represents a block node. | ||
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
#[YieldReady] | ||
class BlockNode extends Node | ||
{ | ||
public function __construct(string $name, Node $body, int $lineno, ?string $tag = null) | ||
|
@@ -37,14 +39,7 @@ public function compile(Compiler $compiler): void | |
|
||
$compiler | ||
->subcompile($this->getNode('body')) | ||
; | ||
|
||
if (!$this->getNode('body') instanceof NodeOutputInterface && $compiler->getEnvironment()->useYield()) { | ||
// needed when body doesn't yield anything | ||
$compiler->write("yield '';\n"); | ||
} | ||
|
||
$compiler | ||
->write("return; yield '';\n") // needed when body doesn't yield anything | ||
->outdent() | ||
->write("}\n\n") | ||
; | ||
|
Oops, something went wrong.