Skip to content

Commit

Permalink
MicroPresenter: removal of callback from parameters during canonizati…
Browse files Browse the repository at this point in the history
…on [Closes nette/routing#9]
  • Loading branch information
dg committed Feb 8, 2021
1 parent 68e1ffa commit f57d5cc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Application/MicroPresenter.php
Expand Up @@ -61,24 +61,27 @@ public function run(Application\Request $request): Application\Response
{
$this->request = $request;

$params = $request->getParameters();
$callback = $params['callback'] ?? null;
unset($params['callback']);

if (!is_object($callback) || !is_callable($callback)) {
throw new Application\BadRequestException('Parameter callback is not a valid closure.');
}

if (
$this->httpRequest
&& $this->router
&& !$this->httpRequest->isAjax()
&& ($request->isMethod('get') || $request->isMethod('head'))
) {
$refUrl = $this->httpRequest->getUrl()->withoutUserInfo();
$url = $this->router->constructUrl($request->toArray(), $refUrl);
$url = $this->router->constructUrl($params, $refUrl);
if ($url !== null && !$refUrl->isEqual($url)) {
return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
}
}

$params = $request->getParameters();
$callback = $params['callback'] ?? null;
if (!is_object($callback) || !is_callable($callback)) {
throw new Application\BadRequestException('Parameter callback is not a valid closure.');
}
$reflection = Nette\Utils\Callback::toReflection($callback);

if ($this->context) {
Expand Down

0 comments on commit f57d5cc

Please sign in to comment.