Skip to content

Commit 90a3da6

Browse files
committed
Remove context argument from partialResolver closure
This is an internal class which shouldn't be part of the public API.
1 parent 5efc90b commit 90a3da6

4 files changed

Lines changed: 5 additions & 13 deletions

File tree

src/Compiler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,8 @@ private function resolvePartial(string &$name): ?string
769769
if (isset($this->context->partials[$name])) {
770770
return $this->context->partials[$name];
771771
}
772-
if ($this->context->partialResolver) {
773-
return ($this->context->partialResolver)($this->context, $name);
772+
if ($this->context->options->partialResolver) {
773+
return ($this->context->options->partialResolver)($name);
774774
}
775775
return null;
776776
}

src/Context.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace DevTheorem\Handlebars;
44

5-
use Closure;
6-
75
/**
86
* @internal
97
*/
@@ -14,7 +12,6 @@ final class Context
1412
* @param array<string, string> $partialCode
1513
* @param array<string, true> $usedHelpers
1614
* @param array<string, string> $partials
17-
* @param null|Closure(Context, string):(string|null) $partialResolver
1815
* @param array<mixed> $partialBlock
1916
* @param array<mixed> $inlinePartial
2017
* @param array<string, callable> $helpers
@@ -28,20 +25,18 @@ public function __construct(
2825
public int $partialBlockId = 0,
2926
public array $usedHelpers = [],
3027
public array $partials = [],
31-
public ?Closure $partialResolver = null,
3228
public array $partialBlock = [],
3329
public array $inlinePartial = [],
3430
public array $helpers = [],
3531
) {
3632
$this->partials = $options->partials;
37-
$this->partialResolver = $options->partialResolver;
3833
$this->helpers = $options->helpers;
3934
}
4035

4136
/**
4237
* Update from another context.
4338
*/
44-
public function merge(Context $context): void
39+
public function merge(self $context): void
4540
{
4641
$this->helpers = $context->helpers;
4742
$this->partials = $context->partials;

src/Options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* @param array<string, callable> $helpers
1111
* @param array<string, string> $partials
12-
* @param null|Closure(Context, string):(string|null) $partialResolver
12+
* @param null|Closure(string):(string|null) $partialResolver
1313
*/
1414
public function __construct(
1515
public bool $knownHelpersOnly = false,

tests/RegressionTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace DevTheorem\Handlebars\Test;
44

5-
use DevTheorem\Handlebars\Context;
65
use DevTheorem\Handlebars\Handlebars;
76
use DevTheorem\Handlebars\HelperOptions;
87
use DevTheorem\Handlebars\Options;
@@ -2321,9 +2320,7 @@ public static function issueProvider(): array
23212320
[
23222321
'template' => '{{>foo}} and {{>bar}}',
23232322
'options' => new Options(
2324-
partialResolver: function (Context $context, string $name) {
2325-
return "PARTIAL: $name";
2326-
},
2323+
partialResolver: fn(string $name) => "PARTIAL: $name",
23272324
),
23282325
'expected' => 'PARTIAL: foo and PARTIAL: bar',
23292326
],

0 commit comments

Comments
 (0)