Skip to content

Commit 5abc596

Browse files
committed
Presenter: added requestToUrl(), taken out from createRequest()
1 parent a8d5d07 commit 5abc596

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/Application/UI/Presenter.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -898,43 +898,45 @@ protected function createRequest(Component $component, string $destination, arra
898898
$args[self::FLASH_KEY] = $this->getFlashKey();
899899
}
900900

901-
$this->lastCreatedRequest = new Application\Request(
902-
$presenter,
903-
Application\Request::FORWARD,
904-
$args,
905-
[],
906-
[]
907-
);
901+
$this->lastCreatedRequest = new Application\Request($presenter, Application\Request::FORWARD, $args);
908902
$this->lastCreatedRequestFlag = ['current' => $current];
909903

910-
if ($mode === 'forward' || $mode === 'test') {
911-
return NULL;
912-
}
904+
return $mode === 'forward' || $mode === 'test'
905+
? NULL
906+
: $this->requestToUrl($this->lastCreatedRequest, $mode === 'link' && $scheme === FALSE) . $fragment;
907+
}
913908

914-
// CONSTRUCT URL
909+
910+
/**
911+
* Converts Request to URL.
912+
* @internal
913+
*/
914+
protected function requestToUrl(Application\Request $request, $relative = NULL): string
915+
{
915916
if ($this->refUrlCache === NULL) {
916917
$this->refUrlCache = new Http\Url($this->httpRequest->getUrl());
917918
$this->refUrlCache->setPath($this->httpRequest->getUrl()->getScriptPath());
918919
}
919920
if (!$this->router) {
920921
throw new Nette\InvalidStateException('Unable to generate URL, service Router has not been set.');
921922
}
922-
$url = $this->router->constructUrl($this->lastCreatedRequest, $this->refUrlCache);
923+
924+
$url = $this->router->constructUrl($request, $this->refUrlCache);
923925
if ($url === NULL) {
924-
unset($args[self::ACTION_KEY]);
925-
$params = urldecode(http_build_query($args, '', ', '));
926-
throw new InvalidLinkException("No route for $presenter:$action($params)");
926+
$params = $request->getParameters();
927+
unset($params[self::ACTION_KEY]);
928+
$params = urldecode(http_build_query($params, '', ', '));
929+
throw new InvalidLinkException("No route for {$request->getPresenterName()}:{$request->getParameter('action')}($params)");
927930
}
928931

929-
// make URL relative if possible
930-
if ($mode === 'link' && $scheme === FALSE && !$this->absoluteUrls) {
932+
if ($relative === NULL ? !$this->absoluteUrls : $relative) {
931933
$hostUrl = $this->refUrlCache->getHostUrl() . '/';
932934
if (strncmp($url, $hostUrl, strlen($hostUrl)) === 0) {
933935
$url = substr($url, strlen($hostUrl) - 1);
934936
}
935937
}
936938

937-
return $url . $fragment;
939+
return $url;
938940
}
939941

940942

0 commit comments

Comments
 (0)