Skip to content

Commit

Permalink
Merge branch 'master' into patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
dg authored Sep 10, 2024
2 parents 83880f2 + 43f2a02 commit 3491c0d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['8.1', '8.2', '8.3']
php: ['8.1', '8.2', '8.3', '8.4']

fail-fast: false

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": "8.1 - 8.3",
"php": "8.1 - 8.4",
"nette/component-model": "^3.1",
"nette/http": "^3.3",
"nette/routing": "^3.1",
Expand Down
8 changes: 6 additions & 2 deletions src/Bridges/ApplicationDI/LatteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getConfigSchema(): Nette\Schema\Schema
'strictTypes' => Expect::bool(false),
'strictParsing' => Expect::bool(false),
'phpLinter' => Expect::string(),
'variables' => Expect::array([]),
'locale' => Expect::string(),
]);
}

Expand All @@ -60,7 +60,8 @@ public function loadConfiguration(): void
->addSetup('setAutoRefresh', [$this->debugMode])
->addSetup('setStrictTypes', [$config->strictTypes])
->addSetup('setStrictParsing', [$config->strictParsing])
->addSetup('enablePhpLinter', [$config->phpLinter]);
->addSetup('enablePhpLinter', [$config->phpLinter])
->addSetup('setLocale', [$config->locale]);

$this->addExtension(new Statement(ApplicationLatte\UIExtension::class, [$builder::literal('$control')]));

Expand All @@ -72,6 +73,9 @@ public function loadConfiguration(): void
}

foreach ($config->extensions as $extension) {
if ($extension === Latte\Essential\TranslatorExtension::class) {
$extension = new Statement($extension, [new Nette\DI\Definitions\Reference(Nette\Localization\Translator::class)]);
}
$this->addExtension($extension);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/ApplicationDI/PresenterFactoryCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function __invoke(string $class): Nette\Application\IPresenter

if ($this->touchToRefresh && class_exists($class)) {
touch($this->touchToRefresh);
header('Refresh: 3');
echo "The DI container does not know the $class class. I will refresh it in 3 seconds.";
echo 'Class ' . htmlspecialchars($class) . ' was not found in DI container.<br><br>If you just created this presenter, it should be enough to refresh the page. It will happen automatically in 5 seconds.<br><br>Otherwise, please check the configuration of your DI container.';
header('Refresh: 5');
exit;
}

Expand Down
42 changes: 42 additions & 0 deletions tests/Bridges.DI/LatteExtension.translator.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* Test: LatteExtension passes Translator to TranslatorExtension
*/

declare(strict_types=1);

use Nette\DI;
use Tester\Assert;

require __DIR__ . '/../bootstrap.php';


class Translator implements Nette\Localization\Translator
{
public function translate(Stringable|string $message, ...$parameters): string|Stringable
{
return '';
}
}

$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
latte:
extensions:
- Latte\Essential\TranslatorExtension
services:
- Translator
', 'neon'));

$compiler = new DI\Compiler;
$compiler->addExtension('latte', new Nette\Bridges\ApplicationDI\LatteExtension(''));
$code = $compiler->addConfig($config)->compile();
eval($code);

$container = new Container;

$latte = $container->getService('nette.latteFactory')->create();
$extensions = Assert::with($latte, fn() => $this->extensions);
Assert::equal(new Latte\Essential\TranslatorExtension(new Translator), $extensions[3]);

0 comments on commit 3491c0d

Please sign in to comment.