-
-
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.
Replace "use_yield" by
#[YieldReady]
on nodes
- Loading branch information
1 parent
7f5958c
commit 3d3caec
Showing
52 changed files
with
397 additions
and
684 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
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,25 @@ | ||
<?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 | ||
{ | ||
public function getNodeVisitors(): array | ||
{ | ||
return [new YieldNotReadyNodeVisitor()]; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -24,6 +24,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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
#[YieldReady] | ||
class BlockNode extends Node | ||
{ | ||
public function __construct(string $name, Node $body, int $lineno, ?string $tag = null) | ||
|
@@ -37,14 +38,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") | ||
; | ||
|
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
#[YieldReady] | ||
class BlockReferenceNode extends Node implements NodeOutputInterface | ||
{ | ||
public function __construct(string $name, int $lineno, ?string $tag = null) | ||
|
@@ -28,16 +29,9 @@ public function __construct(string $name, int $lineno, ?string $tag = null) | |
|
||
public function compile(Compiler $compiler): void | ||
{ | ||
if ($compiler->getEnvironment()->useYield()) { | ||
$compiler | ||
->addDebugInfo($this) | ||
->write(sprintf("yield from \$this->unwrap()->yieldBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name'))) | ||
; | ||
} else { | ||
$compiler | ||
->addDebugInfo($this) | ||
->write(sprintf("\$this->displayBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name'))) | ||
; | ||
} | ||
$compiler | ||
->addDebugInfo($this) | ||
->write(sprintf("yield from \$this->unwrap()->yieldBlock('%s', \$context, \$blocks);\n", $this->getAttribute('name'))) | ||
; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
#[YieldReady] | ||
class BodyNode extends Node | ||
{ | ||
} |
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
* | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
#[YieldReady] | ||
class CaptureNode extends Node | ||
{ | ||
public function __construct(Node $body, int $lineno, ?string $tag = null) | ||
|
@@ -27,62 +28,25 @@ public function __construct(Node $body, int $lineno, ?string $tag = null) | |
|
||
public function compile(Compiler $compiler): void | ||
{ | ||
if ($compiler->getEnvironment()->useYield()) { | ||
if ($this->getAttribute('raw')) { | ||
$compiler->raw("implode('', iterator_to_array("); | ||
} else { | ||
$compiler->raw("('' === \$tmp = implode('', iterator_to_array("); | ||
} | ||
if ($this->getAttribute('with_blocks')) { | ||
$compiler->raw("(function () use (&\$context, \$macros, \$blocks) {\n"); | ||
} else { | ||
$compiler->raw("(function () use (&\$context, \$macros) {\n"); | ||
} | ||
$compiler | ||
->indent() | ||
->subcompile($this->getNode('body')) | ||
->outdent() | ||
->write("})() ?? new \EmptyIterator()))") | ||
; | ||
if (!$this->getAttribute('raw')) { | ||
$compiler->raw(") ? '' : new Markup(\$tmp, \$this->env->getCharset())"); | ||
} | ||
$compiler->raw(';'); | ||
|
||
return; | ||
if ($this->getAttribute('raw')) { | ||
$compiler->raw("implode('', iterator_to_array("); | ||
} else { | ||
$compiler->raw("('' === \$tmp = implode('', iterator_to_array("); | ||
} | ||
|
||
if ($this->getAttribute('with_blocks')) { | ||
$compiler->raw("(function () use (&\$context, \$macros, \$blocks) {\n"); | ||
} else { | ||
$compiler->raw("(function () use (&\$context, \$macros) {\n"); | ||
} | ||
$compiler->indent(); | ||
if ($compiler->getEnvironment()->isDebug()) { | ||
$compiler->write("ob_start();\n"); | ||
} else { | ||
$compiler->write("ob_start(function () { return ''; });\n"); | ||
} | ||
$compiler | ||
->write("try {\n") | ||
->indent() | ||
->subcompile($this->getNode('body')) | ||
->raw("\n") | ||
; | ||
if ($this->getAttribute('raw')) { | ||
$compiler->write("return ob_get_contents();\n"); | ||
} else { | ||
$compiler->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Markup(\$tmp, \$this->env->getCharset());\n"); | ||
} | ||
$compiler | ||
->outdent() | ||
->write("} finally {\n") | ||
->indent() | ||
->write("ob_end_clean();\n") | ||
->outdent() | ||
->write("}\n") | ||
->outdent() | ||
->write('})();') | ||
->write("})() ?? new \EmptyIterator()))") | ||
; | ||
if (!$this->getAttribute('raw')) { | ||
$compiler->raw(") ? '' : new Markup(\$tmp, \$this->env->getCharset())"); | ||
} | ||
$compiler->raw(';'); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
/** | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
#[YieldReady] | ||
class CheckSecurityCallNode extends Node | ||
{ | ||
public function compile(Compiler $compiler) | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
/** | ||
* @author Fabien Potencier <[email protected]> | ||
*/ | ||
#[YieldReady] | ||
class CheckSecurityNode extends Node | ||
{ | ||
private $usedFilters; | ||
|
Oops, something went wrong.