Skip to content

Commit

Permalink
LatteFactory: $control is passed to create() (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 20, 2024
1 parent e2c2688 commit b46947b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/Bridges/ApplicationDI/LatteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]));
Expand Down
3 changes: 2 additions & 1 deletion src/Bridges/ApplicationLatte/LatteFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
4 changes: 0 additions & 4 deletions src/Bridges/ApplicationLatte/TemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(), '/')
Expand Down
14 changes: 0 additions & 14 deletions tests/Bridges.DI/LatteExtension.basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b46947b

Please sign in to comment.