Skip to content

Commit

Permalink
neon with bom (#101)
Browse files Browse the repository at this point in the history
* neon with bom fix

* Update TranslationExtensionTest.phpt

* Update TranslationExtensionTest.phpt

* Update TranslationExtensionTest.phpt

* Update composer.json
  • Loading branch information
aleswita committed Jun 16, 2022
1 parent 9796ce3 commit 8f0f772
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"nette/di": "^3.0.6",
"nette/finder": "^2.5.2",
"nette/http": "^3.0",
"nette/neon": "^3.0",
"nette/neon": "^3.3.1",
"nette/schema": "^1.0",
"nette/routing": "^3.0",
"nette/utils": "^3.2.1",
Expand Down
6 changes: 2 additions & 4 deletions src/Loaders/DatabaseAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ public function load(
throw new InvalidArgument('Parameter resource must be string.');
}

$content = @file_get_contents($resource); // @ -> prevent E_WARNING and thrown an exception

if ($content === false) {
if (!\is_readable($resource)) {
throw new InvalidArgument('Something wrong with resource file "' . $resource . '".');
}

/** @var array<string, string> $settings */
$settings = Neon::decode($content);
$settings = Neon::decodeFile($resource);

$config = [
'table' => $settings['table'] ?? $domain,
Expand Down
8 changes: 3 additions & 5 deletions src/Loaders/Neon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Contributte\Translation\Loaders;

use Contributte\Translation\Exceptions\InvalidArgument;
use Nette;
use Nette\Neon\Neon as NetteNeon;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Loader\ArrayLoader;
use Symfony\Component\Translation\Loader\LoaderInterface;
Expand All @@ -26,13 +26,11 @@ public function load(
throw new InvalidArgument('Parameter resource must be string.');
}

$content = @file_get_contents($resource); // @ -> prevent E_WARNING and thrown an exception

if ($content === false) {
if (!\is_readable($resource)) {
throw new InvalidArgument('Something wrong with resource file "' . $resource . '".');
}

$messages = Nette\Neon\Neon::decode($content);
$messages = NetteNeon::decodeFile($resource);

$catalogue = parent::load($messages ?? [], $locale, $domain);

Expand Down
10 changes: 1 addition & 9 deletions tests/Tests/DI/TranslationExtensionTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,7 @@ final class TranslationExtensionTest extends TestAbstract
Assert::count(1, $tracyPanel->getIgnoredResources());
Assert::count(1, $panel->getIgnoredResources());

$foo = $tracyPanel->getIgnoredResources();
$foo = end($foo);
Assert::same('messages', end($foo));
Assert::true(Strings::contains(key($foo), 'messages.cs_CZ.neon'));

$foo = $panel->getIgnoredResources();
$foo = end($foo);
Assert::same('messages', end($foo));
Assert::true(Strings::contains(key($foo), 'messages.cs_CZ.neon'));
Assert::count(2, $panel->getIgnoredResources()['cs_CZ']);

$symfonyTranslator = $container->getByType(TranslatorInterface::class);
Assert::same($translator, $symfonyTranslator);
Expand Down
2 changes: 1 addition & 1 deletion tests/Tests/TranslatorTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ final class TranslatorTest extends TestAbstract
Assert::count(1, $dom->find('tr[class="contributte-translation-missing-translation"]'));
Assert::count(1, $dom->find('tr[class="contributte-translation-locale-resolvers"]'));
Assert::count(4, $dom->find('tr[class="contributte-translation-resources"]'));// lang/another_domain.en_US.neon, lang/messages+intl-icu.en_US.neon, lang/messages.en_US.neon, lang_overloading/messages.en_US.neon
Assert::count(1, $dom->find('tr[class="contributte-translation-ignored-resources"]'));// lang/messages.cs_CZ.neon
Assert::count(2, $dom->find('tr[class="contributte-translation-ignored-resources"]'));// lang/messages.cs_CZ.neon

$psrLogger = new class() extends AbstractLogger {

Expand Down
2 changes: 2 additions & 0 deletions tests/lang/file_with_BOM.cs_CZ.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# comment
bom: 'BOM'

0 comments on commit 8f0f772

Please sign in to comment.