Skip to content

Commit

Permalink
Presenter::argsToParams() computes default values for mandatory param…
Browse files Browse the repository at this point in the history
…eters with built-in typehint
  • Loading branch information
dg committed Jan 13, 2016
1 parent 9c62388 commit 9869e52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,6 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
continue;
}

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

if ($param->isDefaultValueAvailable()) {
$def = $param->getDefaultValue();
} else {
$def = NULL;
if (!$isClass) {
settype($def, $type);
}
}
if ($args[$name] === $def || ($def === NULL && $args[$name] === '')) {
$args[$name] = NULL; // value transmit is unnecessary
}
Expand Down
2 changes: 1 addition & 1 deletion tests/UI/Presenter.link().php7.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TestPresenter extends Application\UI\Presenter
Assert::same('/index.php?var1=20&action=default&do=hint&presenter=Test', $this->link('hint!', ['var1' => $this->var1 * 2]));
Assert::same('/index.php?y=2&action=default&do=hint&presenter=Test', $this->link('hint!', 1, 2));
Assert::same('/index.php?y=2&bool=1&str=1&action=default&do=hint&presenter=Test', $this->link('hint!', '1', '2', TRUE, TRUE));
Assert::same('/index.php?y=0&bool=0&str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', 0, FALSE, FALSE));
Assert::same('/index.php?str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', 0, FALSE, FALSE));
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', ['str' => '', 'var2' => '']));
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', [1]));
Assert::same('#error: Argument $x passed to TestPresenter::handleHint() must be int, array given.', $this->link('hint!', [1], (object) [1]));
Expand Down

0 comments on commit 9869e52

Please sign in to comment.