Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 24 additions & 25 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,16 @@ protected function getArguments(Hook $hook, array $values, array $requestParams)
$existsInValues = \array_key_exists($key, $values);
$paramExists = $existsInRequest || $existsInValues;

$arg = $existsInRequest ? $requestParams[$key] : $param['default'];
if (\is_callable($arg)) {
$arg = \call_user_func_array($arg, $this->getResources($param['injections']));
if ($existsInRequest) {
$arg = $requestParams[$key];
} else {
if (!is_string($param['default']) && \is_callable($param['default'])) {
$arg = \call_user_func_array($param['default'], $this->getResources($param['injections']));
} else {
$arg = $param['default'];
}
}

$value = $existsInValues ? $values[$key] : $arg;

if (!$param['skipValidation']) {
Expand Down
16 changes: 16 additions & 0 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ public function testCanGetDefaultValueWithFunction(): void
\ob_end_clean();

$this->assertEquals('first-second-second', $result);

/** Try to pass a param that is a PHP callable */
$route = new Route('GET', '/path');
$route
->param('x', '', new Text(200), 'x param', true, ['first', 'second'])
->action(function ($x) {
echo $x;
});

$request = new UtopiaRequestTest();
$request::_setParams(['x' => 'count']);
$this->app->execute($route, $request, new Response());
$result = \ob_get_contents();
\ob_end_clean();

$this->assertEquals('count', $result);
}

public function testCanExecuteRoute(): void
Expand Down