Skip to content

Commit f230978

Browse files
committed
back compatible solution
1 parent 6739750 commit f230978

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

src/Application/LinkGenerator.php src/Application/DefaultLinkGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/**
1818
* Link generator.
1919
*/
20-
final class LinkGenerator implements ILinkGenerator
20+
final class DefaultLinkGenerator implements ILinkGenerator
2121
{
2222
use Nette\SmartObject;
2323

src/Bridges/ApplicationDI/ApplicationExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function loadConfiguration()
104104

105105
$builder->addDefinition($this->prefix('linkGenerator'))
106106
->setType(Nette\Application\ILinkGenerator::class)
107-
->setFactory(Nette\Application\LinkGenerator::class, [
107+
->setFactory(Nette\Application\DefaultLinkGenerator::class, [
108108
1 => new Definitions\Statement([new Definitions\Statement('@Nette\Http\IRequest::getUrl'), 'withoutUserInfo']),
109109
]);
110110

src/compatibility-intf.php

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ class_alias(\Nette\Routing\Router::class, IRouter::class);
2424
class_alias(Response::class, IResponse::class);
2525
}
2626

27+
if (false) {
28+
/** @deprecated use ILinkGenerator */
29+
interface LinkGenerator
30+
{
31+
}
32+
} elseif (!interface_exists(LinkGenerator::class)) {
33+
class_alias(\Nette\Application\ILinkGenerator::class, LinkGenerator::class);
34+
}
35+
2736
namespace Nette\Application\UI;
2837

2938
if (false) {

tests/Bridges.DI/ApplicationExtension.basic.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ test('', function () {
2525
$container = new Container1;
2626
Assert::type(Nette\Application\Application::class, $container->getService('application'));
2727
Assert::type(Nette\Application\PresenterFactory::class, $container->getService('nette.presenterFactory'));
28-
Assert::type(Nette\Application\LinkGenerator::class, $container->getService('application.linkGenerator'));
28+
Assert::type(Nette\Application\DefaultLinkGenerator::class, $container->getService('application.linkGenerator'));
2929
});

tests/Routers/LinkGenerator.phpt

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace ModuleModule {
3939

4040
namespace {
4141

42-
use Nette\Application\LinkGenerator;
42+
use Nette\Application\DefaultLinkGenerator;
4343
use Nette\Application\PresenterFactory;
4444
use Nette\Application\Routers;
4545
use Nette\Http;
@@ -50,7 +50,7 @@ namespace {
5050

5151

5252
test('', function () use ($pf) {
53-
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\UrlScript('http://nette.org/en/'), $pf);
53+
$generator = new DefaultLinkGenerator(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\UrlScript('http://nette.org/en/'), $pf);
66+
$generator = new DefaultLinkGenerator(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\UrlScript('http://nette.org/en/'), $pf);
72+
$generator = new DefaultLinkGenerator(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\UrlScript('http://nette.org/en/'), $pf);
78+
$generator = new DefaultLinkGenerator(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\UrlScript('http://nette.org/en/'));
84+
$generator = new DefaultLinkGenerator(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:'));
@@ -94,7 +94,7 @@ namespace {
9494

9595

9696
test('', function () {
97-
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\UrlScript('http://nette.org/en/'));
97+
$generator = new DefaultLinkGenerator(new Routers\SimpleRouter, new Http\UrlScript('http://nette.org/en/'));
9898
$generator2 = $generator->withReferenceUrl('http://nette.org/cs/');
9999
Assert::same('http://nette.org/en/?action=default&presenter=Homepage', $generator->link('Homepage:default'));
100100
Assert::same('http://nette.org/cs/?action=default&presenter=Homepage', $generator2->link('Homepage:default'));

0 commit comments

Comments
 (0)