From 78fad1aafe206fcf29744de37a2d5a104e29c002 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 11 Jan 2021 02:05:48 +0100 Subject: [PATCH 1/7] events: added default values & removed magic --- composer.json | 2 +- src/Application/Application.php | 31 ++++++++++--------- src/Application/UI/Component.php | 4 +-- src/Application/UI/Form.php | 4 +-- src/Application/UI/Presenter.php | 13 ++++---- .../ApplicationLatte/TemplateFactory.php | 4 +-- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index bd2527883..6f7e3bfec 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "nette/component-model": "^3.0", "nette/http": "^3.0.2", "nette/routing": "~3.0.0", - "nette/utils": "^3.2" + "nette/utils": "^3.2.1" }, "suggest": { "nette/forms": "Allows to use Nette\\Application\\UI\\Form", diff --git a/src/Application/Application.php b/src/Application/Application.php index 92cf4a59a..6e3351c7f 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -11,6 +11,7 @@ use Nette; use Nette\Routing\Router; +use Nette\Utils\Arrays; /** @@ -30,22 +31,22 @@ class Application public $errorPresenter; /** @var callable[]&(callable(Application $sender): void)[]; Occurs before the application loads presenter */ - public $onStartup; + public $onStartup = []; /** @var callable[]&(callable(Application $sender, \Throwable $e = null): void)[]; Occurs before the application shuts down */ - public $onShutdown; + public $onShutdown = []; /** @var callable[]&(callable(Application $sender, Request $request): void)[]; Occurs when a new request is received */ - public $onRequest; + public $onRequest = []; /** @var callable[]&(callable(Application $sender, IPresenter $presenter): void)[]; Occurs when a presenter is created */ - public $onPresenter; + public $onPresenter = []; /** @var callable[]&(callable(Application $sender, Response $response): void)[]; Occurs when a new response is ready for dispatch */ - public $onResponse; + public $onResponse = []; /** @var callable[]&(callable(Application $sender, \Throwable $e): void)[]; Occurs when an unhandled exception occurs in the application */ - public $onError; + public $onError = []; /** @var Request[] */ private $requests = []; @@ -85,23 +86,23 @@ public function __construct( public function run(): void { try { - $this->onStartup($this); + Arrays::invoke($this->onStartup, $this); $this->processRequest($this->createInitialRequest()); - $this->onShutdown($this); + Arrays::invoke($this->onShutdown, $this); } catch (\Throwable $e) { - $this->onError($this, $e); + Arrays::invoke($this->onError, $this, $e); if ($this->catchExceptions && $this->errorPresenter) { try { $this->processException($e); - $this->onShutdown($this, $e); + Arrays::invoke($this->onShutdown, $this, $e); return; } catch (\Throwable $e) { - $this->onError($this, $e); + Arrays::invoke($this->onError, $this, $e); } } - $this->onShutdown($this, $e); + Arrays::invoke($this->onShutdown, $this, $e); throw $e; } } @@ -140,7 +141,7 @@ public function processRequest(Request $request): void } $this->requests[] = $request; - $this->onRequest($this, $request); + Arrays::invoke($this->onRequest, $this, $request); if ( !$request->isMethod($request::FORWARD) @@ -156,7 +157,7 @@ public function processRequest(Request $request): void ? $e : new BadRequestException($e->getMessage(), 0, $e); } - $this->onPresenter($this, $this->presenter); + Arrays::invoke($this->onPresenter, $this, $this->presenter); $response = $this->presenter->run(clone $request); if ($response instanceof Responses\ForwardResponse) { @@ -164,7 +165,7 @@ public function processRequest(Request $request): void goto process; } - $this->onResponse($this, $response); + Arrays::invoke($this->onResponse, $this, $response); $response->send($this->httpRequest, $this->httpResponse); } diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index 39ab36ddc..f66097bd4 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -27,7 +27,7 @@ abstract class Component extends Nette\ComponentModel\Container implements Signa use Nette\ComponentModel\ArrayAccess; /** @var callable[]&(callable(Component $sender): void)[]; Occurs when component is attached to presenter */ - public $onAnchor; + public $onAnchor = []; /** @var array */ protected $params = []; @@ -78,7 +78,7 @@ protected function validateParent(Nette\ComponentModel\IContainer $parent): void parent::validateParent($parent); $this->monitor(Presenter::class, function (Presenter $presenter): void { $this->loadState($presenter->popGlobalParameters($this->getUniqueId())); - $this->onAnchor($this); + Nette\Utils\Arrays::invoke($this->onAnchor, $this); }); } diff --git a/src/Application/UI/Form.php b/src/Application/UI/Form.php index 398973d3d..16917255d 100644 --- a/src/Application/UI/Form.php +++ b/src/Application/UI/Form.php @@ -18,7 +18,7 @@ class Form extends Nette\Forms\Form implements SignalReceiver { /** @var callable[]&(callable(Form $sender): void)[]; Occurs when form is attached to presenter */ - public $onAnchor; + public $onAnchor = []; /** @var bool */ private $sameSiteProtection = true; @@ -57,7 +57,7 @@ protected function validateParent(Nette\ComponentModel\IContainer $parent): void } } - $this->onAnchor($this); + Nette\Utils\Arrays::invoke($this->onAnchor, $this); }); } diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 8a7ff47ba..1261b0070 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -14,6 +14,7 @@ use Nette\Application\Helpers; use Nette\Application\Responses; use Nette\Http; +use Nette\Utils\Arrays; /** @@ -49,13 +50,13 @@ abstract class Presenter extends Control implements Application\IPresenter public $invalidLinkMode; /** @var callable[]&(callable(Presenter $sender): void)[]; Occurs when the presenter is starting */ - public $onStartup; + public $onStartup = []; /** @var callable[]&(callable(Presenter $sender): void)[]; Occurs when the presenter is rendering after beforeRender */ - public $onRender; + public $onRender = []; /** @var callable[]&(callable(Presenter $sender, Response $response): void)[]; Occurs when the presenter is shutting down */ - public $onShutdown; + public $onShutdown = []; /** @var bool automatically call canonicalize() */ public $autoCanonicalize = true; @@ -203,7 +204,7 @@ public function run(Application\Request $request): Application\Response $this->initGlobalParameters(); $this->checkRequirements(static::getReflection()); - $this->onStartup($this); + Arrays::invoke($this->onStartup, $this); $this->startup(); if (!$this->startupCheck) { $class = static::getReflection()->getMethod('startup')->getDeclaringClass()->getName(); @@ -230,7 +231,7 @@ public function run(Application\Request $request): Application\Response // RENDERING VIEW $this->beforeRender(); - $this->onRender($this); + Arrays::invoke($this->onRender, $this); // calls $this->render() $this->tryCall(static::formatRenderMethod($this->view), $this->params); $this->afterRender(); @@ -268,7 +269,7 @@ public function run(Application\Request $request): Application\Response $this->response = new Responses\VoidResponse; } - $this->onShutdown($this, $this->response); + Arrays::invoke($this->onShutdown, $this, $this->response); $this->shutdown($this->response); return $this->response; diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index cfabc6f9e..2b11503a9 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -22,7 +22,7 @@ class TemplateFactory implements UI\TemplateFactory use Nette\SmartObject; /** @var callable[]&(callable(Template $template): void)[]; Occurs when a new template is created */ - public $onCreate; + public $onCreate = []; /** @var LatteFactory */ private $latteFactory; @@ -140,7 +140,7 @@ public function createTemplate(UI\Control $control = null, string $class = null) } $latte->addProvider('cacheStorage', $this->cacheStorage); - $this->onCreate($template); + Nette\Utils\Arrays::invoke($this->onCreate, $template); return $template; } From 4a2d940fb65dee32a647f58be95d67eedc901424 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 12 Jan 2021 12:14:44 +0100 Subject: [PATCH 2/7] refactoring --- src/Application/Application.php | 2 +- src/Application/UI/Presenter.php | 4 +-- src/Bridges/ApplicationDI/LatteExtension.php | 27 ++++++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/Application/Application.php b/src/Application/Application.php index 6e3351c7f..41c851aa3 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -179,7 +179,7 @@ public function processException(\Throwable $e): void $this->httpResponse->setCode($e instanceof BadRequestException ? ($e->getHttpCode() ?: 404) : 500); } - $args = ['exception' => $e, 'request' => end($this->requests) ?: null]; + $args = ['exception' => $e, 'request' => Arrays::last($this->requests) ?: null]; if ($this->presenter instanceof UI\Presenter) { try { $this->presenter->forward(":$this->errorPresenter:", $args); diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 1261b0070..34b5a85c3 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -463,7 +463,7 @@ public function sendTemplate(Template $template = null): void } if (!$template->getFile()) { - $file = strtr(reset($files), '/', DIRECTORY_SEPARATOR); + $file = strtr(Arrays::first($files), '/', DIRECTORY_SEPARATOR); $this->error("Page not found. Missing template '$file'."); } } @@ -489,7 +489,7 @@ public function findLayoutTemplateFile(): ?string } if ($this->layout) { - $file = strtr(reset($files), '/', DIRECTORY_SEPARATOR); + $file = strtr(Arrays::first($files), '/', DIRECTORY_SEPARATOR); throw new Nette\FileNotFoundException("Layout not found. Missing template '$file'."); } return null; diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index cc3b1034a..68877aaf6 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -11,6 +11,8 @@ use Latte; use Nette; +use Nette\Bridges\ApplicationLatte; +use Nette\Schema\Expect; /** @@ -29,20 +31,17 @@ public function __construct(string $tempDir, bool $debugMode = false) { $this->tempDir = $tempDir; $this->debugMode = $debugMode; + } - $this->config = new class { - /** @var bool */ - public $xhtml = false; - - /** @var string[] */ - public $macros = []; - - /** @var ?string */ - public $templateClass; - /** @var bool */ - public $strictTypes = false; - }; + public function getConfigSchema(): Nette\Schema\Schema + { + return Expect::structure([ + 'xhtml' => Expect::bool(false), + 'macros' => Expect::arrayOf('string'), + 'templateClass' => Expect::string(), + 'strictTypes' => Expect::bool(false), + ]); } @@ -56,7 +55,7 @@ public function loadConfiguration() $builder = $this->getContainerBuilder(); $latteFactory = $builder->addFactoryDefinition($this->prefix('latteFactory')) - ->setImplement(Nette\Bridges\ApplicationLatte\LatteFactory::class) + ->setImplement(ApplicationLatte\LatteFactory::class) ->getResultDefinition() ->setFactory(Latte\Engine::class) ->addSetup('setTempDirectory', [$this->tempDir]) @@ -70,7 +69,7 @@ public function loadConfiguration() $builder->addDefinition($this->prefix('templateFactory')) ->setType(Nette\Application\UI\TemplateFactory::class) - ->setFactory(Nette\Bridges\ApplicationLatte\TemplateFactory::class) + ->setFactory(ApplicationLatte\TemplateFactory::class) ->setArguments(['templateClass' => $config->templateClass]); foreach ($config->macros as $macro) { From 68c05459caab9d4087a9ca957924c5738f6b7451 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 16 Jan 2021 04:19:09 +0100 Subject: [PATCH 3/7] LatteExtension: initializes Latte Panel, added option 'debugger' --- src/Bridges/ApplicationDI/LatteExtension.php | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 68877aaf6..bebe82bb7 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -13,6 +13,7 @@ use Nette; use Nette\Bridges\ApplicationLatte; use Nette\Schema\Expect; +use Tracy; /** @@ -37,6 +38,7 @@ public function __construct(string $tempDir, bool $debugMode = false) public function getConfigSchema(): Nette\Schema\Schema { return Expect::structure([ + 'debugger' => Expect::anyOf(true, false, 'all'), 'xhtml' => Expect::bool(false), 'macros' => Expect::arrayOf('string'), 'templateClass' => Expect::string(), @@ -83,6 +85,34 @@ public function loadConfiguration() } + public function beforeCompile() + { + $builder = $this->getContainerBuilder(); + + if ( + $this->debugMode + && ($this->config->debugger ?? $builder->getByType(Tracy\Bar::class)) + && class_exists(Latte\Bridges\Tracy\LattePanel::class) + ) { + $factory = $builder->getDefinition($this->prefix('templateFactory')); + $factory->addSetup([self::class, 'initLattePanel'], [$factory, 'all' => $this->config->debugger === 'all']); + } + } + + + public static function initLattePanel(ApplicationLatte\TemplateFactory $factory, Tracy\Bar $bar, bool $all = false) + { + $factory->onCreate[] = function (ApplicationLatte\Template $template) use ($bar, $all) { + if ($all || $template->control instanceof Nette\Application\UI\Presenter) { + $bar->addPanel(new Latte\Bridges\Tracy\LattePanel( + $template->getLatte(), + $all ? (new \ReflectionObject($template->control))->getShortName() : '' + )); + } + }; + } + + public function addMacro(string $macro): void { $builder = $this->getContainerBuilder(); From 24984e4b92b86c6af4ad8255dd4c5e9de210eafc Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 16 Jan 2021 22:49:13 +0100 Subject: [PATCH 4/7] LatteExtension: option 'xhtml' is deprecated --- src/Bridges/ApplicationDI/LatteExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index bebe82bb7..c9f177c4b 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -39,7 +39,7 @@ public function getConfigSchema(): Nette\Schema\Schema { return Expect::structure([ 'debugger' => Expect::anyOf(true, false, 'all'), - 'xhtml' => Expect::bool(false), + 'xhtml' => Expect::bool(false)->deprecated(), 'macros' => Expect::arrayOf('string'), 'templateClass' => Expect::string(), 'strictTypes' => Expect::bool(false), From 908a0db72b7f2e01585fa7a1b49dccc670d95260 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 19 Jan 2021 01:20:10 +0100 Subject: [PATCH 5/7] Component::createComponent() warns on non-presenter components [Closes nette/forms#147] --- src/Application/UI/Component.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Application/UI/Component.php b/src/Application/UI/Component.php index f66097bd4..7eb9edad6 100644 --- a/src/Application/UI/Component.php +++ b/src/Application/UI/Component.php @@ -73,6 +73,18 @@ public function getUniqueId(): string } + + protected function createComponent(string $name): ?Nette\ComponentModel\IComponent + { + $res = parent::createComponent($name); + if (!$res instanceof SignalReceiver && !$res instanceof StatePersistent) { + $type = get_class($res); + trigger_error("It seems that component '$name' of type $type is not intended to for in the Presenter.", E_USER_NOTICE); + } + return $res; + } + + protected function validateParent(Nette\ComponentModel\IContainer $parent): void { parent::validateParent($parent); From 67397504dcc2fdd11be46b8859e64969df138ca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jura=CC=81sek?= Date: Thu, 14 Jan 2021 16:58:25 +0100 Subject: [PATCH 6/7] LinkGenerator: extract interface --- src/Application/ILinkGenerator.php | 26 +++++++++++++++++++ src/Application/LinkGenerator.php | 2 +- .../ApplicationDI/ApplicationExtension.php | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/Application/ILinkGenerator.php diff --git a/src/Application/ILinkGenerator.php b/src/Application/ILinkGenerator.php new file mode 100644 index 000000000..e83966103 --- /dev/null +++ b/src/Application/ILinkGenerator.php @@ -0,0 +1,26 @@ +addDefinition($this->prefix('linkGenerator')) + ->setType(Nette\Application\ILinkGenerator::class) ->setFactory(Nette\Application\LinkGenerator::class, [ 1 => new Definitions\Statement([new Definitions\Statement('@Nette\Http\IRequest::getUrl'), 'withoutUserInfo']), ]); From 2f18bdcb8f04226705770426650ee6cd2558294d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jura=CC=81sek?= Date: Tue, 19 Jan 2021 13:49:12 +0100 Subject: [PATCH 7/7] back compatible solution --- ...{LinkGenerator.php => DefaultLinkGenerator.php} | 4 ++-- src/Application/ILinkGenerator.php | 2 +- src/Bridges/ApplicationDI/ApplicationExtension.php | 2 +- src/compatibility-intf.php | 9 +++++++++ tests/Bridges.DI/ApplicationExtension.basic.phpt | 2 +- tests/Routers/LinkGenerator.phpt | 14 +++++++------- 6 files changed, 21 insertions(+), 12 deletions(-) rename src/Application/{LinkGenerator.php => DefaultLinkGenerator.php} (95%) diff --git a/src/Application/LinkGenerator.php b/src/Application/DefaultLinkGenerator.php similarity index 95% rename from src/Application/LinkGenerator.php rename to src/Application/DefaultLinkGenerator.php index 60d779dcf..7092109d8 100644 --- a/src/Application/LinkGenerator.php +++ b/src/Application/DefaultLinkGenerator.php @@ -17,7 +17,7 @@ /** * Link generator. */ -final class LinkGenerator implements ILinkGenerator +final class DefaultLinkGenerator implements ILinkGenerator { use Nette\SmartObject; @@ -93,7 +93,7 @@ public function link(string $dest, array $params = []): string } - public function withReferenceUrl(string $url): self + public function withReferenceUrl(string $url): ILinkGenerator { return new self( $this->router, diff --git a/src/Application/ILinkGenerator.php b/src/Application/ILinkGenerator.php index e83966103..65db594a9 100644 --- a/src/Application/ILinkGenerator.php +++ b/src/Application/ILinkGenerator.php @@ -22,5 +22,5 @@ interface ILinkGenerator */ public function link(string $dest, array $params = []): string; - public function withReferenceUrl(string $url): self; + public function withReferenceUrl(string $url): ILinkGenerator; } diff --git a/src/Bridges/ApplicationDI/ApplicationExtension.php b/src/Bridges/ApplicationDI/ApplicationExtension.php index d658cd63d..03a638ec5 100644 --- a/src/Bridges/ApplicationDI/ApplicationExtension.php +++ b/src/Bridges/ApplicationDI/ApplicationExtension.php @@ -104,7 +104,7 @@ public function loadConfiguration() $builder->addDefinition($this->prefix('linkGenerator')) ->setType(Nette\Application\ILinkGenerator::class) - ->setFactory(Nette\Application\LinkGenerator::class, [ + ->setFactory(Nette\Application\DefaultLinkGenerator::class, [ 1 => new Definitions\Statement([new Definitions\Statement('@Nette\Http\IRequest::getUrl'), 'withoutUserInfo']), ]); diff --git a/src/compatibility-intf.php b/src/compatibility-intf.php index fff947040..d4b9d1c8e 100644 --- a/src/compatibility-intf.php +++ b/src/compatibility-intf.php @@ -24,6 +24,15 @@ class_alias(\Nette\Routing\Router::class, IRouter::class); class_alias(Response::class, IResponse::class); } +if (false) { + /** @deprecated use ILinkGenerator */ + interface LinkGenerator + { + } +} elseif (!interface_exists(LinkGenerator::class)) { + class_alias(\Nette\Application\ILinkGenerator::class, LinkGenerator::class); +} + namespace Nette\Application\UI; if (false) { diff --git a/tests/Bridges.DI/ApplicationExtension.basic.phpt b/tests/Bridges.DI/ApplicationExtension.basic.phpt index 7f31806fc..cfda062b2 100644 --- a/tests/Bridges.DI/ApplicationExtension.basic.phpt +++ b/tests/Bridges.DI/ApplicationExtension.basic.phpt @@ -25,5 +25,5 @@ test('', function () { $container = new Container1; Assert::type(Nette\Application\Application::class, $container->getService('application')); Assert::type(Nette\Application\PresenterFactory::class, $container->getService('nette.presenterFactory')); - Assert::type(Nette\Application\LinkGenerator::class, $container->getService('application.linkGenerator')); + Assert::type(Nette\Application\DefaultLinkGenerator::class, $container->getService('application.linkGenerator')); }); diff --git a/tests/Routers/LinkGenerator.phpt b/tests/Routers/LinkGenerator.phpt index 6761e67a9..b99313eec 100644 --- a/tests/Routers/LinkGenerator.phpt +++ b/tests/Routers/LinkGenerator.phpt @@ -39,7 +39,7 @@ namespace ModuleModule { namespace { - use Nette\Application\LinkGenerator; + use Nette\Application\DefaultLinkGenerator; use Nette\Application\PresenterFactory; use Nette\Application\Routers; use Nette\Http; @@ -50,7 +50,7 @@ namespace { test('', function () use ($pf) { - $generator = new LinkGenerator(new Routers\SimpleRouter, new Http\UrlScript('http://nette.org/en/'), $pf); + $generator = new DefaultLinkGenerator(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\UrlScript('http://nette.org/en/'), $pf); + $generator = new DefaultLinkGenerator(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\UrlScript('http://nette.org/en/'), $pf); + $generator = new DefaultLinkGenerator(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\UrlScript('http://nette.org/en/'), $pf); + $generator = new DefaultLinkGenerator(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\UrlScript('http://nette.org/en/')); + $generator = new DefaultLinkGenerator(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:')); @@ -94,7 +94,7 @@ namespace { test('', function () { - $generator = new LinkGenerator(new Routers\SimpleRouter, new Http\UrlScript('http://nette.org/en/')); + $generator = new DefaultLinkGenerator(new Routers\SimpleRouter, new Http\UrlScript('http://nette.org/en/')); $generator2 = $generator->withReferenceUrl('http://nette.org/cs/'); Assert::same('http://nette.org/en/?action=default&presenter=Homepage', $generator->link('Homepage:default')); Assert::same('http://nette.org/cs/?action=default&presenter=Homepage', $generator2->link('Homepage:default'));