Skip to content

Commit e57b0f9

Browse files
committed
normalized callable to Closure
1 parent a835d88 commit e57b0f9

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

src/Latte/Compiler/TemplateParser.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class TemplateParser
4242
private string $contentType;
4343
private int $counter = 0;
4444
private ?Tag $tag = null;
45-
private $lastResolver;
45+
private ?\Closure $lastResolver = null;
4646
private \WeakMap $lookFor;
4747

4848

@@ -83,11 +83,15 @@ public function parse(string $template): Nodes\TemplateNode
8383
}
8484

8585

86-
public function parseFragment(callable $resolver, ?callable $after = null): FragmentNode
86+
/**
87+
* @param \Closure(FragmentNode): ?Node $resolver
88+
* @param (\Closure(FragmentNode): void)|null $after
89+
*/
90+
public function parseFragment(\Closure $resolver, ?\Closure $after = null): FragmentNode
8791
{
8892
$res = new FragmentNode;
8993
$save = [$this->lastResolver, $this->tag];
90-
$this->lastResolver = $resolver;
94+
$this->lastResolver = $resolver(...);
9195
try {
9296
while (!$this->stream->peek()->isEnd()) {
9397
if ($node = $resolver($res)) {

src/Latte/Engine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public function getPolicy(bool $effective = false): ?Policy
428428

429429
public function setExceptionHandler(callable $handler): static
430430
{
431-
$this->providers->coreExceptionHandler = $handler;
431+
$this->providers->coreExceptionHandler = $handler(...);
432432
return $this;
433433
}
434434

src/Latte/Essential/TranslatorExtension.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@
2525
*/
2626
final class TranslatorExtension extends Latte\Extension
2727
{
28-
/** @var callable|Translator|null */
29-
private $translator;
28+
private ?\Closure $translator;
3029

3130

3231
public function __construct(
3332
callable|Translator|null $translator,
3433
private ?string $key = null,
3534
) {
36-
$this->translator = $translator;
37-
if ($translator instanceof Translator) {
38-
$this->translator = $translator->translate(...);
39-
}
35+
$this->translator = match (true) {
36+
$translator === null => null,
37+
$translator instanceof Translator => $translator->translate(...),
38+
default => $translator(...),
39+
};
4040
}
4141

4242

src/Latte/Extension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public function beforeRender(Runtime\Template $template): void
9494

9595
public static function order(callable $subject, array|string $before = [], array|string $after = []): \stdClass
9696
{
97+
$subject = $subject(...);
9798
return (object) get_defined_vars();
9899
}
99100
}

src/Latte/Sandbox/RuntimeChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function callMethod(mixed $object, mixed $method, array $args, bool $null
5353
public function closure(mixed $callable): \Closure
5454
{
5555
self::checkCallable($callable);
56-
return \Closure::fromCallable($callable);
56+
return $callable(...);
5757
}
5858

5959

0 commit comments

Comments
 (0)