Skip to content

Commit 56c5e11

Browse files
committed
Router::constructUrl() typehint changed from Nette\Http\Url to UrlScript (BC break)
1 parent 802d943 commit 56c5e11

19 files changed

+37
-43
lines changed

src/Application/IRouter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ function match(Nette\Http\IRequest $httpRequest): ?array;
2828
/**
2929
* Constructs absolute URL from array.
3030
*/
31-
function constructUrl(array $params, Nette\Http\Url $refUrl): ?string;
31+
function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string;
3232
}

src/Application/LinkGenerator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ final class LinkGenerator
2222
/** @var IRouter */
2323
private $router;
2424

25-
/** @var Nette\Http\Url */
25+
/** @var Nette\Http\UrlScript */
2626
private $refUrl;
2727

2828
/** @var IPresenterFactory|null */
2929
private $presenterFactory;
3030

3131

32-
public function __construct(IRouter $router, Nette\Http\Url $refUrl, IPresenterFactory $presenterFactory = null)
32+
public function __construct(IRouter $router, Nette\Http\UrlScript $refUrl, IPresenterFactory $presenterFactory = null)
3333
{
3434
$this->router = $router;
3535
$this->refUrl = $refUrl;

src/Application/MicroPresenter.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public function run(Application\Request $request): Application\IResponse
5858
$this->request = $request;
5959

6060
if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
61-
$refUrl = clone $this->httpRequest->getUrl();
62-
$url = $this->router->constructUrl($request->toArray(), $refUrl->setPath($refUrl->getScriptPath()));
61+
$refUrl = $this->httpRequest->getUrl();
62+
$url = $this->router->constructUrl($request->toArray(), $refUrl);
6363
if ($url !== null && !$this->httpRequest->getUrl()->isEqual($url)) {
6464
return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
6565
}

src/Application/Routers/CliRouter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
9191
/**
9292
* This router is only unidirectional.
9393
*/
94-
public function constructUrl(array $params, Nette\Http\Url $refUrl): ?string
94+
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
9595
{
9696
return null;
9797
}

src/Application/Routers/Route.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
257257
/**
258258
* Constructs absolute URL from array.
259259
*/
260-
public function constructUrl(array $params, Nette\Http\Url $refUrl): ?string
260+
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
261261
{
262262
if ($this->flags & self::ONE_WAY) {
263263
return null;

src/Application/Routers/RouteList.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
5454
/**
5555
* Constructs absolute URL from array.
5656
*/
57-
public function constructUrl(array $params, Nette\Http\Url $refUrl): ?string
57+
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
5858
{
5959
if ($this->cachedRoutes === null) {
6060
$this->warmupCache();

src/Application/Routers/SimpleRouter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function match(Nette\Http\IRequest $httpRequest): ?array
8181
/**
8282
* Constructs absolute URL from array.
8383
*/
84-
public function constructUrl(array $params, Nette\Http\Url $refUrl): ?string
84+
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
8585
{
8686
if ($this->flags & self::ONE_WAY) {
8787
return null;

src/Application/UI/Presenter.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ abstract class Presenter extends Control implements Application\IPresenter
129129
/** @var ITemplateFactory */
130130
private $templateFactory;
131131

132-
/** @var Nette\Http\Url */
132+
/** @var Nette\Http\UrlScript */
133133
private $refUrlCache;
134134

135135

@@ -911,8 +911,8 @@ public static function parseDestination(string $destination): array
911911
protected function requestToUrl(Application\Request $request, bool $relative = null): string
912912
{
913913
if ($this->refUrlCache === null) {
914-
$this->refUrlCache = new Http\Url($this->httpRequest->getUrl());
915-
$this->refUrlCache->setPath($this->httpRequest->getUrl()->getScriptPath());
914+
$url = $this->httpRequest->getUrl();
915+
$this->refUrlCache = new Http\UrlScript($url->getHostUrl() . $url->getScriptPath());
916916
}
917917
if (!$this->router) {
918918
throw new Nette\InvalidStateException('Unable to generate URL, service Router has not been set.');

tests/Application/Presenter.twoDomains.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ class TestPresenter extends Application\UI\Presenter
2424

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

3029
$presenter = new TestPresenter;
3130
$presenter->injectPrimary(

tests/Bridges.DI/RoutingExtension.cache.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MyRouter implements Nette\Application\IRouter
2525
}
2626

2727

28-
public function constructUrl(array $params, Nette\Http\Url $refUrl): ?string
28+
public function constructUrl(array $params, Nette\Http\UrlScript $refUrl): ?string
2929
{
3030
}
3131

tests/Routers/LinkGenerator.phpt

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace {
5050

5151

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

6464

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

7070

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

7676

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

8282

8383
test(function () {
84-
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\Url('http://nette.org/en/'));
84+
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\UrlScript('http://nette.org/en/'));
8585
Assert::same('http://nette.org/en/?action=default&presenter=Homepage', $generator->link('Homepage:default'));
8686
Assert::same('http://nette.org/en/?action=default&presenter=Module%3AMy', $generator->link('Module:My:default'));
8787
Assert::same('http://nette.org/en/?presenter=Module%3AMy', $generator->link('Module:My:'));

tests/Routers/Route.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

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

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

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

4141
function testRouteOut(Nette\Application\IRouter $route, array $params = []): ?string
4242
{
43-
$url = new Nette\Http\Url('http://example.com');
43+
$url = new Nette\Http\UrlScript('http://example.com');
4444
return $route->constructUrl($params, $url);
4545
}

tests/Routers/Route.secured.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
declare(strict_types=1);
88

99
use Nette\Application\Routers\Route;
10-
use Nette\Http\Url;
10+
use Nette\Http\UrlScript;
1111
use Tester\Assert;
1212

1313

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

2323
$url = $route->constructUrl(
2424
['presenter' => 'Presenter', 'param' => 'any'],
25-
new Url('https://example.org')
25+
new UrlScript('https://example.org')
2626
);
2727
Assert::same('https://example.org/any', $url);

tests/Routers/Route.withHost.secured.phpt

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
declare(strict_types=1);
88

99
use Nette\Application\Routers\Route;
10-
use Nette\Http\Url;
10+
use Nette\Http\UrlScript;
1111
use Tester\Assert;
1212

1313

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

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

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

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

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

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

tests/Routers/SimpleRouter.module.phpt

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ $router = new Application\Routers\SimpleRouter([
1818
'module' => 'main:sub',
1919
]);
2020

21-
$url = new Http\UrlScript('http://nette.org/file.php');
22-
$url->setScriptPath('/file.php');
21+
$url = new Http\Url('http://nette.org/file.php', '/file.php');
2322
$url->setQuery([
2423
'presenter' => 'myPresenter',
2524
]);
26-
$httpRequest = new Http\Request($url);
25+
$httpRequest = new Http\Request(new Http\UrlScript($url));
2726

2827
$req = $router->match($httpRequest);
2928
Assert::same('main:sub:myPresenter', $req['presenter']);

tests/Routers/SimpleRouter.phpt

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ $router = new SimpleRouter([
1919
'any' => 'anyvalue',
2020
]);
2121

22-
$url = new Http\UrlScript('http://nette.org/file.php');
23-
$url->setScriptPath('/file.php');
22+
$url = new Http\Url('http://nette.org/file.php');
2423
$url->setQuery([
2524
'presenter' => 'myPresenter',
2625
'action' => 'action',
2726
'id' => '12',
2827
'test' => 'testvalue',
2928
]);
30-
$httpRequest = new Http\Request($url);
29+
$httpRequest = new Http\Request(new Http\UrlScript($url, '/file.php'));
3130

3231
$params = $router->match($httpRequest);
3332
Assert::same([

tests/UI/Component.isLinkCurrent().asserts.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ function callIsComponentLinkCurrent(
2525
$destination,
2626
array $args
2727
): bool {
28-
$url = new Http\UrlScript('http://localhost/index.php');
29-
$url->setScriptPath('/index.php');
28+
$url = new Http\UrlScript('http://localhost/index.php', '/index.php');
3029
$presenterFactory = Mockery::mock(Nette\Application\IPresenterFactory::class);
3130
$presenterFactory->shouldReceive('getPresenterClass')->andReturn('TestPresenter');
3231

tests/UI/Presenter.link().persistent.phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ Assert::same([
121121
], ThirdPresenter::getReflection()->getPersistentParams());
122122

123123

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

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

tests/UI/Presenter.link().phpt

+1-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ class OtherPresenter extends TestPresenter
281281
}
282282

283283

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

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

0 commit comments

Comments
 (0)