Skip to content

Commit

Permalink
Bugfix: File path handling for override (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefro authored Oct 19, 2023
1 parent c4dc742 commit 6506dfc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/LangCountry.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,11 @@ private function getDataFromFile(?string $lang_country): array
throw new Exception('The lang_country session is not set');
}

if (file_exists(lang_path('lang-country-overrides') . $lang_country . '.json')) {
$resource = lang_path('lang-country-overrides') . $lang_country . '.json';
$filename = $lang_country . '.json';
if (file_exists(lang_path('lang-country-overrides/' . $filename))) {
$resource = lang_path('lang-country-overrides/' . $filename);
} else {
$resource = __DIR__ . '/LangCountryData/' . $lang_country . '.json';
$resource = __DIR__ . '/LangCountryData/' . $filename;
}

return json_decode(file_get_contents($resource), true);
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/LangCountry/LangCountryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,13 @@ function ($fallbackBasedOnCurrentLocale, $langCountrySession, $appLocale, $expec

$file = __DIR__ . '/../../Support/Files/lang-country-overrides/nl-NL.json';
$dir = lang_path('lang-country-overrides');
$filename = 'nl-NL.json';

if (! is_dir($dir)) {
mkdir($dir);
}
if (! is_file($dir)) {
$dest = $dir . 'nl-NL.json';
$dest = lang_path('lang-country-overrides/' . $filename);
}

copy($file, $dest);
Expand All @@ -316,7 +317,7 @@ function ($fallbackBasedOnCurrentLocale, $langCountrySession, $appLocale, $expec
->and(\LangCountry::name())->toEqual('Nederlands override!');

// Remove test files from testbench
unlink(lang_path('lang-country-overrides') . 'nl-NL.json');
unlink(lang_path('lang-country-overrides/' . $filename));
rmdir(lang_path('lang-country-overrides'));
});

Expand Down

0 comments on commit 6506dfc

Please sign in to comment.