Permalink
Browse files

Router::constructUrl() typehint changed from Nette\Http\Url to UrlScr…

…ipt (BC break)
  • Loading branch information...
dg committed Feb 12, 2019
1 parent 802d943 commit 620797e57aa247de1c3f7ec105858595aa903846
@@ -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;
}
@@ -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;
@@ -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;
}
@@ -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;
@@ -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();
@@ -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;
@@ -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;
@@ -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.');
@@ -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(
@@ -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
{
}
@@ -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:'));
@@ -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:'));
@@ -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);
@@ -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);
}
@@ -7,7 +7,7 @@
declare(strict_types=1);
use Nette\Application\Routers\Route;
use Nette\Http\Url;
use Nette\Http\UrlScript;
use Tester\Assert;
@@ -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);
@@ -7,7 +7,7 @@
declare(strict_types=1);
use Nette\Application\Routers\Route;
use Nette\Http\Url;
use Nette\Http\UrlScript;
use Tester\Assert;
@@ -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);
@@ -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);
@@ -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']);
@@ -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([
@@ -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');
@@ -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')
@@ -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')

0 comments on commit 620797e

Please sign in to comment.