Skip to content

Commit a33ac9a

Browse files
committed
removed support for Latte 2
1 parent 1fec65e commit a33ac9a

File tree

59 files changed

+17
-2041
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+17
-2041
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"nette/forms": "^3.2",
3232
"nette/robot-loader": "^4.0",
3333
"nette/security": "^3.2",
34-
"latte/latte": "^2.10.2 || ^3.0.12",
34+
"latte/latte": "^3.0.12",
3535
"tracy/tracy": "^2.9",
3636
"mockery/mockery": "^1.6",
3737
"phpstan/phpstan-nette": "^1.0",
@@ -42,7 +42,7 @@
4242
"nette/di": "<3.2",
4343
"nette/forms": "<3.2",
4444
"nette/schema": "<1.3",
45-
"latte/latte": "<2.7.1 || >=3.0.0 <3.0.12 || >=3.1",
45+
"latte/latte": "<3.0.12",
4646
"tracy/tracy": "<2.9"
4747
},
4848
"autoload": {

src/Bridges/ApplicationDI/LatteExtension.php

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public function getConfigSchema(): Nette\Schema\Schema
3333
{
3434
return Expect::structure([
3535
'debugger' => Expect::anyOf(true, false, 'all'),
36-
'macros' => Expect::arrayOf('string'),
3736
'extensions' => Expect::arrayOf('string|Nette\DI\Definitions\Statement'),
3837
'templateClass' => Expect::string(),
3938
'strictTypes' => Expect::bool(false),
@@ -52,36 +51,26 @@ public function loadConfiguration(): void
5251
$config = $this->config;
5352
$builder = $this->getContainerBuilder();
5453

55-
$latteFactory = $builder->addFactoryDefinition($this->prefix('latteFactory'))
54+
$builder->addFactoryDefinition($this->prefix('latteFactory'))
5655
->setImplement(ApplicationLatte\LatteFactory::class)
5756
->getResultDefinition()
5857
->setFactory(Latte\Engine::class)
5958
->addSetup('setTempDirectory', [$this->tempDir])
6059
->addSetup('setAutoRefresh', [$this->debugMode])
61-
->addSetup('setStrictTypes', [$config->strictTypes]);
62-
63-
if (version_compare(Latte\Engine::VERSION, '3', '<')) {
64-
foreach ($config->macros as $macro) {
65-
$this->addMacro($macro);
66-
}
67-
} else {
68-
$latteFactory->addSetup('setStrictParsing', [$config->strictParsing])
69-
->addSetup('enablePhpLinter', [$config->phpLinter]);
70-
71-
$builder->getDefinition($this->prefix('latteFactory'))
72-
->getResultDefinition()
60+
->addSetup('setStrictTypes', [$config->strictTypes])
61+
->addSetup('setStrictParsing', [$config->strictParsing])
62+
->addSetup('enablePhpLinter', [$config->phpLinter])
7363
->addSetup('?', [$builder::literal('func_num_args() && $service->addExtension(new Nette\Bridges\ApplicationLatte\UIExtension(func_get_arg(0)))')]);
7464

75-
if ($cache = $builder->getByType(Nette\Caching\Storage::class)) {
76-
$this->addExtension(new Statement(Nette\Bridges\CacheLatte\CacheExtension::class, [$builder->getDefinition($cache)]));
77-
}
78-
if (class_exists(Nette\Bridges\FormsLatte\FormsExtension::class)) {
79-
$this->addExtension(new Statement(Nette\Bridges\FormsLatte\FormsExtension::class));
80-
}
65+
if ($cache = $builder->getByType(Nette\Caching\Storage::class)) {
66+
$this->addExtension(new Statement(Nette\Bridges\CacheLatte\CacheExtension::class, [$builder->getDefinition($cache)]));
67+
}
68+
if (class_exists(Nette\Bridges\FormsLatte\FormsExtension::class)) {
69+
$this->addExtension(new Statement(Nette\Bridges\FormsLatte\FormsExtension::class));
70+
}
8171

82-
foreach ($config->extensions as $extension) {
83-
$this->addExtension($extension);
84-
}
72+
foreach ($config->extensions as $extension) {
73+
$this->addExtension($extension);
8574
}
8675

8776
$builder->addDefinition($this->prefix('templateFactory'))
@@ -124,40 +113,12 @@ public static function initLattePanel(
124113
$control = $template->getLatte()->getProviders()['uiControl'] ?? null;
125114
if ($all || $control instanceof Nette\Application\UI\Presenter) {
126115
$name = $all && $control ? (new \ReflectionObject($control))->getShortName() : '';
127-
if (version_compare(Latte\Engine::VERSION, '3', '<')) {
128-
$bar->addPanel(new Latte\Bridges\Tracy\LattePanel($template->getLatte(), $name));
129-
} else {
130-
$template->getLatte()->addExtension(new Latte\Bridges\Tracy\TracyExtension($name));
131-
}
116+
$template->getLatte()->addExtension(new Latte\Bridges\Tracy\TracyExtension($name));
132117
}
133118
};
134119
}
135120

136121

137-
public function addMacro(string $macro): void
138-
{
139-
$builder = $this->getContainerBuilder();
140-
$definition = $builder->getDefinition($this->prefix('latteFactory'))->getResultDefinition();
141-
142-
if (($macro[0] ?? null) === '@') {
143-
if (str_contains($macro, '::')) {
144-
[$macro, $method] = explode('::', $macro);
145-
} else {
146-
$method = 'install';
147-
}
148-
149-
$definition->addSetup('?->onCompile[] = function ($engine) { ?->' . $method . '($engine->getCompiler()); }', ['@self', $macro]);
150-
151-
} else {
152-
if (!str_contains($macro, '::') && class_exists($macro)) {
153-
$macro .= '::install';
154-
}
155-
156-
$definition->addSetup('?->onCompile[] = function ($engine) { ' . $macro . '($engine->getCompiler()); }', ['@self']);
157-
}
158-
}
159-
160-
161122
public function addExtension(Statement|string $extension): void
162123
{
163124
$extension = is_string($extension)

src/Bridges/ApplicationLatte/SnippetBridge.php

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/Bridges/ApplicationLatte/Template.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,7 @@ public function addFunction(string $name, callable $callback): static
9090
*/
9191
public function setTranslator(?Nette\Localization\Translator $translator, ?string $language = null): static
9292
{
93-
if (version_compare(Latte\Engine::VERSION, '3', '<')) {
94-
$this->latte->addFilter(
95-
'translate',
96-
fn(Latte\Runtime\FilterInfo $fi, ...$args): string => $translator === null
97-
? $args[0]
98-
: $translator->translate(...$args),
99-
);
100-
} else {
101-
$this->latte->addExtension(new Latte\Essential\TranslatorExtension($translator, $language));
102-
}
93+
$this->latte->addExtension(new Latte\Essential\TranslatorExtension($translator, $language));
10394
return $this;
10495
}
10596

src/Bridges/ApplicationLatte/TemplateFactory.php

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Nette\Bridges\ApplicationLatte;
1111

12-
use Latte;
1312
use Nette;
1413
use Nette\Application\UI;
1514

@@ -28,7 +27,6 @@ public function __construct(
2827
private readonly LatteFactory $latteFactory,
2928
private readonly ?Nette\Http\IRequest $httpRequest = null,
3029
private readonly ?Nette\Security\User $user = null,
31-
private readonly ?Nette\Caching\Storage $cacheStorage = null,
3230
$templateClass = null,
3331
) {
3432
if ($templateClass && (!class_exists($templateClass) || !is_a($templateClass, Template::class, true))) {
@@ -51,9 +49,7 @@ public function createTemplate(?UI\Control $control = null, ?string $class = nul
5149
$template = new $class($latte);
5250
$presenter = $control?->getPresenterIfExists();
5351

54-
if (version_compare(Latte\Engine::VERSION, '3', '<')) {
55-
$this->setupLatte2($latte, $control, $presenter, $template);
56-
} elseif (!Nette\Utils\Arrays::some($latte->getExtensions(), fn($e) => $e instanceof UIExtension)) {
52+
if (!Nette\Utils\Arrays::some($latte->getExtensions(), fn($e) => $e instanceof UIExtension)) {
5753
$latte->addExtension(new UIExtension($control));
5854
}
5955

@@ -84,55 +80,4 @@ public function createTemplate(?UI\Control $control = null, ?string $class = nul
8480

8581
return $template;
8682
}
87-
88-
89-
private function setupLatte2(
90-
Latte\Engine $latte,
91-
?UI\Control $control,
92-
?UI\Presenter $presenter,
93-
Template $template,
94-
): void
95-
{
96-
if ($latte->onCompile instanceof \Traversable) {
97-
$latte->onCompile = iterator_to_array($latte->onCompile);
98-
}
99-
100-
array_unshift($latte->onCompile, function (Latte\Engine $latte) use ($control, $template): void {
101-
if ($this->cacheStorage) {
102-
$latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro);
103-
}
104-
105-
UIMacros::install($latte->getCompiler());
106-
if (class_exists(Nette\Bridges\FormsLatte\FormMacros::class)) {
107-
Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
108-
}
109-
110-
$control?->templatePrepareFilters($template);
111-
});
112-
113-
$latte->addProvider('cacheStorage', $this->cacheStorage);
114-
115-
if ($control) {
116-
$latte->addProvider('uiControl', $control);
117-
$latte->addProvider('uiPresenter', $presenter);
118-
$latte->addProvider('snippetBridge', new SnippetBridge($control));
119-
if ($presenter) {
120-
$header = $presenter->getHttpResponse()->getHeader('Content-Security-Policy')
121-
?: $presenter->getHttpResponse()->getHeader('Content-Security-Policy-Report-Only');
122-
}
123-
124-
$nonce = $presenter && preg_match('#\s\'nonce-([\w+/]+=*)\'#', (string) $header, $m) ? $m[1] : null;
125-
$latte->addProvider('uiNonce', $nonce);
126-
}
127-
128-
if ($presenter) {
129-
$latte->addFunction('isLinkCurrent', [$presenter, 'isLinkCurrent']);
130-
$latte->addFunction('isModuleCurrent', [$presenter, 'isModuleCurrent']);
131-
}
132-
133-
$latte->addFilter('modifyDate', fn($time, $delta, $unit = null) => $time
134-
? Nette\Utils\DateTime::from($time)->modify($delta . $unit)
135-
: null);
136-
137-
}
13883
}

0 commit comments

Comments
 (0)