Skip to content

Commit

Permalink
Router::constructUrl() typehint changed from Nette\Http\Url to UrlScr…
Browse files Browse the repository at this point in the history
…ipt (BC break)
  • Loading branch information
dg committed Feb 12, 2019
1 parent 802d943 commit 56c5e11
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/Application/IRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ function match(Nette\Http\IRequest $httpRequest): ?array;
/**
* Constructs absolute URL from array.
*/
function constructUrl(array $params, Nette\Http\Url $refUrl): ?string;
function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string;
}
4 changes: 2 additions & 2 deletions src/Application/LinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ final class LinkGenerator
/** @var IRouter */
private $router;

/** @var Nette\Http\Url */
/** @var Nette\Http\UrlScript */
private $refUrl;

/** @var IPresenterFactory|null */
private $presenterFactory;


public function __construct(IRouter $router, Nette\Http\Url $refUrl, IPresenterFactory $presenterFactory = null)
public function __construct(IRouter $router, Nette\Http\UrlScript $refUrl, IPresenterFactory $presenterFactory = null)
{
$this->router = $router;
$this->refUrl = $refUrl;
Expand Down
4 changes: 2 additions & 2 deletions src/Application/MicroPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public function run(Application\Request $request): Application\IResponse
$this->request = $request;

if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
$refUrl = clone $this->httpRequest->getUrl();
$url = $this->router->constructUrl($request->toArray(), $refUrl->setPath($refUrl->getScriptPath()));
$refUrl = $this->httpRequest->getUrl();
$url = $this->router->constructUrl($request->toArray(), $refUrl);
if ($url !== null && !$this->httpRequest->getUrl()->isEqual($url)) {
return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Routers/CliRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
/**
* This router is only unidirectional.
*/
public function constructUrl(array $params, Nette\Http\Url $refUrl): ?string
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Routers/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
/**
* Constructs absolute URL from array.
*/
public function constructUrl(array $params, Nette\Http\Url $refUrl): ?string
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
{
if ($this->flags & self::ONE_WAY) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Routers/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
/**
* Constructs absolute URL from array.
*/
public function constructUrl(array $params, Nette\Http\Url $refUrl): ?string
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
{
if ($this->cachedRoutes === null) {
$this->warmupCache();
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Routers/SimpleRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
/**
* Constructs absolute URL from array.
*/
public function constructUrl(array $params, Nette\Http\Url $refUrl): ?string
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
{
if ($this->flags & self::ONE_WAY) {
return null;
Expand Down
6 changes: 3 additions & 3 deletions src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ abstract class Presenter extends Control implements Application\IPresenter
/** @var ITemplateFactory */
private $templateFactory;

/** @var Nette\Http\Url */
/** @var Nette\Http\UrlScript */
private $refUrlCache;


Expand Down Expand Up @@ -911,8 +911,8 @@ public static function parseDestination(string $destination): array
protected function requestToUrl(Application\Request $request, bool $relative = null): string
{
if ($this->refUrlCache === null) {
$this->refUrlCache = new Http\Url($this->httpRequest->getUrl());
$this->refUrlCache->setPath($this->httpRequest->getUrl()->getScriptPath());
$url = $this->httpRequest->getUrl();
$this->refUrlCache = new Http\UrlScript($url->getHostUrl() . $url->getScriptPath());
}
if (!$this->router) {
throw new Nette\InvalidStateException('Unable to generate URL, service Router has not been set.');
Expand Down
3 changes: 1 addition & 2 deletions tests/Application/Presenter.twoDomains.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class TestPresenter extends Application\UI\Presenter

function testLink($domain)
{
$url = new Http\UrlScript('http://' . $domain . '/index.php');
$url->setScriptPath('/index.php');
$url = new Http\UrlScript('http://' . $domain . '/index.php', '/index.php');

$presenter = new TestPresenter;
$presenter->injectPrimary(
Expand Down
2 changes: 1 addition & 1 deletion tests/Bridges.DI/RoutingExtension.cache.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MyRouter implements Nette\Application\IRouter
}


public function constructUrl(array $params, Nette\Http\Url $refUrl): ?string
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
{
}

Expand Down
10 changes: 5 additions & 5 deletions tests/Routers/LinkGenerator.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace {


test(function () use ($pf) {
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\Url('http://nette.org/en/'), $pf);
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\UrlScript('http://nette.org/en/'), $pf);
Assert::same('http://nette.org/en/?action=default&presenter=Homepage', $generator->link('Homepage:default'));
Assert::same('http://nette.org/en/?action=default&presenter=Module%3AMy', $generator->link('Module:My:default'));
Assert::same('http://nette.org/en/?presenter=Module%3AMy', $generator->link('Module:My:'));
Expand All @@ -63,25 +63,25 @@ namespace {


Assert::exception(function () use ($pf) {
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\Url('http://nette.org/en/'), $pf);
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\UrlScript('http://nette.org/en/'), $pf);
$generator->link('default');
}, Nette\Application\UI\InvalidLinkException::class, "Invalid link destination 'default'.");


Assert::exception(function () use ($pf) {
$generator = new LinkGenerator(new Routers\Route('/', 'Product:'), new Http\Url('http://nette.org/en/'), $pf);
$generator = new LinkGenerator(new Routers\Route('/', 'Product:'), new Http\UrlScript('http://nette.org/en/'), $pf);
$generator->link('Homepage:default', ['id' => 10]);
}, Nette\Application\UI\InvalidLinkException::class, 'No route for Homepage:default(id=10)');


Assert::exception(function () use ($pf) {
$generator = new LinkGenerator(new Routers\Route('/', 'Homepage:'), new Http\Url('http://nette.org/en/'), $pf);
$generator = new LinkGenerator(new Routers\Route('/', 'Homepage:'), new Http\UrlScript('http://nette.org/en/'), $pf);
$generator->link('Homepage:missing', [10]);
}, Nette\Application\UI\InvalidLinkException::class, "Unable to pass parameters to action 'Homepage:missing', missing corresponding method.");


test(function () {
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\Url('http://nette.org/en/'));
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\UrlScript('http://nette.org/en/'));
Assert::same('http://nette.org/en/?action=default&presenter=Homepage', $generator->link('Homepage:default'));
Assert::same('http://nette.org/en/?action=default&presenter=Module%3AMy', $generator->link('Module:My:default'));
Assert::same('http://nette.org/en/?presenter=Module%3AMy', $generator->link('Module:My:'));
Expand Down
8 changes: 4 additions & 4 deletions tests/Routers/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

function testRouteIn(Nette\Application\IRouter $route, string $url, array $expectedParams = null, string $expectedUrl = null): void
{
$url = new Nette\Http\UrlScript("http://example.com$url");
$url->setScriptPath('/');
$url->appendQuery([
$urlBuilder = new Nette\Http\Url("http://example.com$url");
$urlBuilder->appendQuery([
'test' => 'testvalue',
'presenter' => 'querypresenter',
]);
$url = new Nette\Http\UrlScript($urlBuilder, '/');

$httpRequest = new Nette\Http\Request($url);

Expand All @@ -40,6 +40,6 @@ function testRouteIn(Nette\Application\IRouter $route, string $url, array $expec

function testRouteOut(Nette\Application\IRouter $route, array $params = []): ?string
{
$url = new Nette\Http\Url('http://example.com');
$url = new Nette\Http\UrlScript('http://example.com');
return $route->constructUrl($params, $url);
}
4 changes: 2 additions & 2 deletions tests/Routers/Route.secured.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
declare(strict_types=1);

use Nette\Application\Routers\Route;
use Nette\Http\Url;
use Nette\Http\UrlScript;
use Tester\Assert;


Expand All @@ -22,6 +22,6 @@ $route = new Route('<param>', [

$url = $route->constructUrl(
['presenter' => 'Presenter', 'param' => 'any'],
new Url('https://example.org')
new UrlScript('https://example.org')
);
Assert::same('https://example.org/any', $url);
10 changes: 5 additions & 5 deletions tests/Routers/Route.withHost.secured.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
declare(strict_types=1);

use Nette\Application\Routers\Route;
use Nette\Http\Url;
use Nette\Http\UrlScript;
use Tester\Assert;


Expand All @@ -23,13 +23,13 @@ $route = new Route('//example.org/test', [

$url = $route->constructUrl(
['presenter' => 'Default', 'action' => 'default'],
new Url('https://example.org')
new UrlScript('https://example.org')
);
Assert::same('https://example.org/test', $url);

$url = $route->constructUrl(
['presenter' => 'Default', 'action' => 'default'],
new Url('https://example.com')
new UrlScript('https://example.com')
);
Assert::same('https://example.org/test', $url);

Expand All @@ -42,12 +42,12 @@ $route = new Route('https://example.org/test', [

$url = $route->constructUrl(
['presenter' => 'Default', 'action' => 'default'],
new Url('https://example.org')
new UrlScript('https://example.org')
);
Assert::same('https://example.org/test', $url);

$url = $route->constructUrl(
['presenter' => 'Default', 'action' => 'default'],
new Url('https://example.com')
new UrlScript('https://example.com')
);
Assert::same('https://example.org/test', $url);
5 changes: 2 additions & 3 deletions tests/Routers/SimpleRouter.module.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ $router = new Application\Routers\SimpleRouter([
'module' => 'main:sub',
]);

$url = new Http\UrlScript('http://nette.org/file.php');
$url->setScriptPath('/file.php');
$url = new Http\Url('http://nette.org/file.php', '/file.php');
$url->setQuery([
'presenter' => 'myPresenter',
]);
$httpRequest = new Http\Request($url);
$httpRequest = new Http\Request(new Http\UrlScript($url));

$req = $router->match($httpRequest);
Assert::same('main:sub:myPresenter', $req['presenter']);
Expand Down
5 changes: 2 additions & 3 deletions tests/Routers/SimpleRouter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ $router = new SimpleRouter([
'any' => 'anyvalue',
]);

$url = new Http\UrlScript('http://nette.org/file.php');
$url->setScriptPath('/file.php');
$url = new Http\Url('http://nette.org/file.php');
$url->setQuery([
'presenter' => 'myPresenter',
'action' => 'action',
'id' => '12',
'test' => 'testvalue',
]);
$httpRequest = new Http\Request($url);
$httpRequest = new Http\Request(new Http\UrlScript($url, '/file.php'));

$params = $router->match($httpRequest);
Assert::same([
Expand Down
3 changes: 1 addition & 2 deletions tests/UI/Component.isLinkCurrent().asserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ function callIsComponentLinkCurrent(
$destination,
array $args
): bool {
$url = new Http\UrlScript('http://localhost/index.php');
$url->setScriptPath('/index.php');
$url = new Http\UrlScript('http://localhost/index.php', '/index.php');
$presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class);
$presenterFactory->shouldReceive('getPresenterClass')->andReturn('TestPresenter');

Expand Down
3 changes: 1 addition & 2 deletions tests/UI/Presenter.link().persistent.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ Assert::same([
], ThirdPresenter::getReflection()->getPersistentParams());


$url = new Http\UrlScript('http://localhost/index.php');
$url->setScriptPath('/index.php');
$url = new Http\UrlScript('http://localhost/index.php', '/index.php');

$presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class);
$presenterFactory->shouldReceive('getPresenterClass')
Expand Down
3 changes: 1 addition & 2 deletions tests/UI/Presenter.link().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ class OtherPresenter extends TestPresenter
}


$url = new Http\UrlScript('http://localhost/index.php');
$url->setScriptPath('/index.php');
$url = new Http\UrlScript('http://localhost/index.php', '/index.php');

$presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class);
$presenterFactory->shouldReceive('getPresenterClass')
Expand Down

0 comments on commit 56c5e11

Please sign in to comment.