Skip to content

Commit 56986e6

Browse files
vranadg
authored andcommitted
LinkGenerator: do not pass defaults of #[Parameter] (#355)
1 parent aa053af commit 56986e6

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/Application/LinkGenerator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ public function createRequest(
170170
trigger_error("Link to deprecated presenter '$presenter' from '{$refPresenter->getName()}:{$refPresenter->getAction()}'.", E_USER_DEPRECATED);
171171
}
172172

173+
foreach (array_intersect_key($reflection->getParameters(), $args) as $name => $param) {
174+
if ($args[$name] === $param['def']) {
175+
$args[$name] = null; // value transmit is unnecessary
176+
}
177+
}
178+
173179
// counterpart of run() & tryCall()
174180
if ($method = $reflection->getActionRenderMethod($action)) {
175181
if ($this->isDeprecated($refPresenter, $method)) {

src/Application/UI/ComponentReflection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function getParameters(): array
5555
];
5656
} elseif ($prop->getAttributes(Attributes\Parameter::class)) {
5757
$params[$prop->getName()] = [
58+
'def' => $prop->hasDefaultValue() ? $prop->getDefaultValue() : null,
5859
'type' => (string) ($prop->getType() ?? 'mixed'),
5960
];
6061
}

tests/UI/ComponentReflection.getParameters().phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Assert::same(
5151
'since' => 'OnePresenter',
5252
],
5353
'yes3' => [
54+
'def' => null,
5455
'type' => 'mixed',
5556
],
5657
],
@@ -60,9 +61,11 @@ Assert::same(
6061
Assert::same(
6162
[
6263
'yes2' => [
64+
'def' => null,
6365
'type' => 'mixed',
6466
],
6567
'yes4' => [
68+
'def' => null,
6669
'type' => 'mixed',
6770
],
6871
'yes1' => [
@@ -71,6 +74,7 @@ Assert::same(
7174
'since' => 'OnePresenter',
7275
],
7376
'yes3' => [
77+
'def' => null,
7478
'type' => 'mixed',
7579
],
7680
],

0 commit comments

Comments
 (0)