diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 977b975..3c93dae 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -16,7 +16,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.2' coverage: none - name: Install composer dependencies diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 66d9301..928ed06 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,7 +13,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.0] + php: [8.2, 8.3] stability: [prefer-lowest, prefer-stable] name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/composer.json b/composer.json index 6689e4b..1a9a51f 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "phpstan/extension-installer": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-phpunit": "^1.0", - "tightenco/jigsaw": "^1.4" + "tightenco/jigsaw": "^1.7" }, "autoload": { "files": [ diff --git a/src/helpers.php b/src/helpers.php index 0fe97f3..9e7bcf3 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -9,7 +9,6 @@ /** * @param mixed $page - * @param string $text * @param ?string $current_locale * @return string The translated text if found, else returns the same given $text */ @@ -29,8 +28,6 @@ function current_path_locale($page): string { $path = trim($page->getPath(), '/'); - $default_locale = $page->defaultLocale ?? packageDefaultLocale(); - /** * - [a-z]{2,3} language code * - [A-Z]{2} region code @@ -41,12 +38,12 @@ function current_path_locale($page): string preg_match($locale_regex, $path, $matches); - return $matches['locale'] ?? $default_locale; + return $matches['locale'] ?? packageDefaultLocale(); } /** * @param mixed $page - * @param ?string $target_locale set to the default locale if null + * @param ?string $target_locale set to the default locale if null * @return string Places $target_locale code in the current path */ function translate_path($page, ?string $target_locale = null): string @@ -56,19 +53,19 @@ function translate_path($page, ?string $target_locale = null): string $current_locale = current_path_locale($page); $partial_path = match (true) { - $current_locale === $page->defaultLocale => $page->getPath(), + $current_locale === packageDefaultLocale($page) => $page->getPath(), default => substr($page->getPath(), strlen($current_locale) + 1), }; return match (true) { - $target_locale === $page->defaultLocale => "{$partial_path}", + $target_locale === packageDefaultLocale($page) => "{$partial_path}", default => "/{$target_locale}{$partial_path}", }; } /** * @param mixed $page - * @param ?string $target_locale set to the default locale if null + * @param ?string $target_locale set to the default locale if null * @return string Places $target_locale code in the current url */ function translate_url($page, ?string $target_locale = null): string @@ -78,8 +75,8 @@ function translate_url($page, ?string $target_locale = null): string /** * @param mixed $page - * @param string $partial_path A path without the language prefix - * @param ?string $target_locale uses the default locale if null + * @param string $partial_path A path without the language prefix + * @param ?string $target_locale uses the default locale if null * @return string A path on the target locale */ function locale_path($page, string $partial_path, ?string $target_locale = null): string @@ -89,15 +86,15 @@ function locale_path($page, string $partial_path, ?string $target_locale = null) $partial_path = '/'.trim($partial_path, '/'); return match (true) { - $target_locale === $page->defaultLocale => $partial_path, + $target_locale === packageDefaultLocale($page) => $partial_path, default => "/{$target_locale}{$partial_path}" }; } /** * @param mixed $page - * @param string $partial_path A path without the language prefix - * @param ?string $target_locale uses the default locale if null + * @param string $partial_path A path without the language prefix + * @param ?string $target_locale uses the default locale if null * @return string A URL on the target locale */ function locale_url($page, string $partial_path, ?string $target_locale = null): string diff --git a/tests/TestCase.php b/tests/TestCase.php index 4731e14..8b9f315 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,6 +3,7 @@ namespace Tests; use PHPUnit\Framework\TestCase as BaseTestCase; +use TightenCo\Jigsaw\Container; // use TightenCo\Jigsaw\File\ConfigFile; @@ -14,8 +15,7 @@ protected function setUp(): void { parent::setUp(); - require __DIR__.'/../vendor/tightenco/jigsaw/jigsaw-core.php'; - $this->app = $container; + $this->app = new Container; // $this->app->bind('config', function ($c) use ($cachePath) { // $config = (new ConfigFile($c['cwd'] . '/config.php', $c['cwd'] . '/helpers.php'))->config; diff --git a/tests/_Mocks/PageMock.php b/tests/_Mocks/PageMock.php index 8070728..55de948 100644 --- a/tests/_Mocks/PageMock.php +++ b/tests/_Mocks/PageMock.php @@ -12,11 +12,6 @@ class PageMock public array $localization = []; - public function __construct() - { - $this->defaultLocale = packageDefaultLocale(); - } - public function setPath(string $path): static { $this->path = '/'.trim($path, '/');