From b46947bb0a8f5b26cc16142fbdc97d4021036fc0 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Sat, 6 Apr 2024 18:44:44 +0200 Subject: [PATCH] LatteFactory: $control is passed to create() (BC break) --- src/Bridges/ApplicationDI/LatteExtension.php | 5 +++-- src/Bridges/ApplicationLatte/LatteFactory.php | 3 ++- src/Bridges/ApplicationLatte/TemplateFactory.php | 4 ---- tests/Bridges.DI/LatteExtension.basic.phpt | 14 -------------- 4 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/Bridges/ApplicationDI/LatteExtension.php b/src/Bridges/ApplicationDI/LatteExtension.php index 18d1362ee..82673aa13 100644 --- a/src/Bridges/ApplicationDI/LatteExtension.php +++ b/src/Bridges/ApplicationDI/LatteExtension.php @@ -59,8 +59,9 @@ public function loadConfiguration(): void ->addSetup('setAutoRefresh', [$this->debugMode]) ->addSetup('setStrictTypes', [$config->strictTypes]) ->addSetup('setStrictParsing', [$config->strictParsing]) - ->addSetup('enablePhpLinter', [$config->phpLinter]) - ->addSetup('?', [$builder::literal('func_num_args() && $service->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension(func_get_arg(0)))')]); + ->addSetup('enablePhpLinter', [$config->phpLinter]); + + $this->addExtension(new Statement(ApplicationLatte\UIExtension::class, [$builder::literal('$control')])); if ($cache = $builder->getByType(Nette\Caching\Storage::class)) { $this->addExtension(new Statement(Nette\Bridges\CacheLatte\CacheExtension::class, [$builder->getDefinition($cache)])); diff --git a/src/Bridges/ApplicationLatte/LatteFactory.php b/src/Bridges/ApplicationLatte/LatteFactory.php index e6d2c8842..71e1ced0c 100644 --- a/src/Bridges/ApplicationLatte/LatteFactory.php +++ b/src/Bridges/ApplicationLatte/LatteFactory.php @@ -10,11 +10,12 @@ namespace Nette\Bridges\ApplicationLatte; use Latte; +use Nette\Application\UI\Control; interface LatteFactory { - function create(/*?Control $control = null*/): Latte\Engine; + function create(?Control $control = null): Latte\Engine; } diff --git a/src/Bridges/ApplicationLatte/TemplateFactory.php b/src/Bridges/ApplicationLatte/TemplateFactory.php index 31acb518c..1f2cbb764 100644 --- a/src/Bridges/ApplicationLatte/TemplateFactory.php +++ b/src/Bridges/ApplicationLatte/TemplateFactory.php @@ -48,10 +48,6 @@ public function createTemplate(?UI\Control $control = null, ?string $class = nul $template = new $class($latte); $presenter = $control?->getPresenterIfExists(); - if (!Nette\Utils\Arrays::some($latte->getExtensions(), fn($e) => $e instanceof UIExtension)) { - $latte->addExtension(new UIExtension($control)); - } - // default parameters $baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->withoutUserInfo()->getBaseUrl(), '/') diff --git a/tests/Bridges.DI/LatteExtension.basic.phpt b/tests/Bridges.DI/LatteExtension.basic.phpt index 34ea641d5..a3a13d48f 100644 --- a/tests/Bridges.DI/LatteExtension.basic.phpt +++ b/tests/Bridges.DI/LatteExtension.basic.phpt @@ -59,20 +59,6 @@ Assert::type(Nette\Bridges\ApplicationLatte\LatteFactory::class, $container->get $latte = $container->getService('nette.latteFactory')->create(); $extensions = Assert::with($latte, fn() => $this->extensions); -Assert::equal([ - new Latte\Essential\CoreExtension, - new Latte\Sandbox\SandboxExtension, - new Nette\Bridges\FormsLatte\FormsExtension, - new MyExtension, - new MyExtension(1), - new MyExtension(2), - new MyExtension, -], $extensions); - -// UIExtension is added -$latte = $container->getService('nette.latteFactory')->create(null); -$extensions = Assert::with($latte, fn() => $this->extensions); - Assert::equal([ new Latte\Essential\CoreExtension, new Latte\Sandbox\SandboxExtension,