Skip to content

Commit 2db833b

Browse files
committed
Node: getIterator() must exists (BC break)
1 parent f3bf01a commit 2db833b

19 files changed

+117
-0
lines changed

src/Latte/Compiler/Nodes/AuxiliaryNode.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ public function print(PrintContext $context): string
2424
{
2525
return ($this->callable)($context);
2626
}
27+
28+
29+
public function &getIterator(): \Generator
30+
{
31+
false && yield;
32+
}
2733
}

src/Latte/Compiler/Nodes/NopNode.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ public function print(PrintContext $context): string
1818
{
1919
return '';
2020
}
21+
22+
23+
public function &getIterator(): \Generator
24+
{
25+
false && yield;
26+
}
2127
}

src/Latte/Compiler/Nodes/Php/IdentifierNode.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@ public function print(PrintContext $context): string
3333
{
3434
return $this->name;
3535
}
36+
37+
38+
public function &getIterator(): \Generator
39+
{
40+
false && yield;
41+
}
3642
}

src/Latte/Compiler/Nodes/Php/NameNode.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,10 @@ public function toCodeString(): string
8686
};
8787
return $prefix . implode('\\', $this->parts);
8888
}
89+
90+
91+
public function &getIterator(): \Generator
92+
{
93+
false && yield;
94+
}
8995
}

src/Latte/Compiler/Nodes/Php/ScalarNode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212

1313
abstract class ScalarNode extends ExpressionNode
1414
{
15+
public function &getIterator(): \Generator
16+
{
17+
false && yield;
18+
}
1519
}

src/Latte/Compiler/Nodes/Php/SuperiorTypeNode.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ public function print(PrintContext $context): string
2626
{
2727
throw new \LogicException('Cannot directly print SuperiorTypeNode');
2828
}
29+
30+
31+
public function &getIterator(): \Generator
32+
{
33+
false && yield;
34+
}
2935
}

src/Latte/Compiler/Nodes/TextNode.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,10 @@ public function isWhitespace(): bool
3434
{
3535
return trim($this->content) === '';
3636
}
37+
38+
39+
public function &getIterator(): \Generator
40+
{
41+
false && yield;
42+
}
3743
}

src/Latte/Compiler/TemplateParser.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ public function parseLatteStatement(): ?Node
238238
throw new \LogicException("Incorrect behavior of {{$startTag->name}} parser, unexpected returned value (on line {$startTag->position->line})");
239239
}
240240

241+
$this->checkNodeCompatibility($node);
242+
241243
if ($this->location === self::LocationHead && $startTag->outputMode !== $startTag::OutputNone) {
242244
$this->location = self::LocationText;
243245
}
@@ -445,4 +447,17 @@ public function isTagAllowed(string $name): bool
445447
{
446448
return !$this->policy || $this->policy->isTagAllowed($name);
447449
}
450+
451+
452+
public function checkNodeCompatibility(Node $node): void
453+
{
454+
static $prev = ['Nette\Bridges\ApplicationLatte\Nodes\NNonceNode' => true];
455+
if (
456+
!isset($prev[$node::class])
457+
&& (new \ReflectionMethod($node, 'getIterator'))->getDeclaringClass()->getName() === Node::class
458+
) {
459+
trigger_error('Class ' . $node::class . ' should contain method getIterator(), see https://bit.ly/latte-666');
460+
}
461+
$prev[$node::class] = true;
462+
}
448463
}

src/Latte/Compiler/TemplateParserHtml.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ private function openNAttrNodes(array $toOpen): array
454454

455455
} elseif ($res instanceof Node) {
456456
$this->parser->ensureIsConsumed($tag);
457+
$this->parser->checkNodeCompatibility($res);
457458
$res->position = $tag->position;
458459
$tag->replaceNAttribute($res);
459460
$this->parser->popTag();
@@ -477,6 +478,7 @@ private function finishNAttrNodes(AreaNode $node, array $toClose): AreaNode
477478
while ([$gen, $tag] = array_pop($toClose)) {
478479
$gen->send([$node, null]);
479480
$node = $gen->getReturn();
481+
$this->parser->checkNodeCompatibility($node);
480482
$node->position = $tag->position;
481483
$this->parser->popTag();
482484
$this->parser->ensureIsConsumed($tag);

src/Latte/Essential/Nodes/ContentTypeNode.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,10 @@ public function print(PrintContext $context): string
7171
)
7272
: '';
7373
}
74+
75+
76+
public function &getIterator(): \Generator
77+
{
78+
false && yield;
79+
}
7480
}

0 commit comments

Comments
 (0)