Skip to content

Commit 9869e52

Browse files
committed
Presenter::argsToParams() computes default values for mandatory parameters with built-in typehint
1 parent 9c62388 commit 9869e52

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Application/UI/Presenter.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,6 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
10351035
continue;
10361036
}
10371037

1038-
$def = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : NULL;
10391038
list($type, $isClass) = PresenterComponentReflection::getParameterType($param);
10401039
if (!PresenterComponentReflection::convertType($args[$name], $type, $isClass)) {
10411040
throw new InvalidLinkException(sprintf(
@@ -1047,6 +1046,14 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
10471046
));
10481047
}
10491048

1049+
if ($param->isDefaultValueAvailable()) {
1050+
$def = $param->getDefaultValue();
1051+
} else {
1052+
$def = NULL;
1053+
if (!$isClass) {
1054+
settype($def, $type);
1055+
}
1056+
}
10501057
if ($args[$name] === $def || ($def === NULL && $args[$name] === '')) {
10511058
$args[$name] = NULL; // value transmit is unnecessary
10521059
}

tests/UI/Presenter.link().php7.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class TestPresenter extends Application\UI\Presenter
3636
Assert::same('/index.php?var1=20&action=default&do=hint&presenter=Test', $this->link('hint!', ['var1' => $this->var1 * 2]));
3737
Assert::same('/index.php?y=2&action=default&do=hint&presenter=Test', $this->link('hint!', 1, 2));
3838
Assert::same('/index.php?y=2&bool=1&str=1&action=default&do=hint&presenter=Test', $this->link('hint!', '1', '2', TRUE, TRUE));
39-
Assert::same('/index.php?y=0&bool=0&str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', 0, FALSE, FALSE));
39+
Assert::same('/index.php?str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', 0, FALSE, FALSE));
4040
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', ['str' => '', 'var2' => '']));
4141
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', [1]));
4242
Assert::same('#error: Argument $x passed to TestPresenter::handleHint() must be int, array given.', $this->link('hint!', [1], (object) [1]));

0 commit comments

Comments
 (0)