From f988a162637d4c1b4140f799dfe0fe9f8dd74f5a Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Wed, 3 Apr 2024 12:30:51 -0300 Subject: [PATCH 1/5] chore: make compatible with newest version of Jigsaw At Jigsaw 1.5.0 was removed the file jigsaw-core.php Signed-off-by: Vitor Mattos --- tests/TestCase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; From 5b6bce85d0d95a5ab0d1381f594e49f4325a52ca Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Wed, 3 Apr 2024 12:32:18 -0300 Subject: [PATCH 2/5] fix: usage of defaultLocale property Need to use the function packageDefaultLocale to prevent problems when defaultLocale is not defined Signed-off-by: Vitor Mattos --- src/helpers.php | 10 ++++------ tests/_Mocks/PageMock.php | 5 ----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/helpers.php b/src/helpers.php index 0fe97f3..be52c68 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -29,8 +29,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,7 +39,7 @@ function current_path_locale($page): string preg_match($locale_regex, $path, $matches); - return $matches['locale'] ?? $default_locale; + return $matches['locale'] ?? packageDefaultLocale(); } /** @@ -56,12 +54,12 @@ 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}", }; } @@ -89,7 +87,7 @@ 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}" }; } 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, '/'); From dccc4251ad8f171634bf08cd6432d1c91dfb1040 Mon Sep 17 00:00:00 2001 From: vitormattos Date: Wed, 3 Apr 2024 15:49:26 +0000 Subject: [PATCH 3/5] Fix styling Signed-off-by: Vitor Mattos --- src/helpers.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/helpers.php b/src/helpers.php index be52c68..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 */ @@ -44,7 +43,7 @@ function current_path_locale($page): string /** * @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 @@ -66,7 +65,7 @@ function translate_path($page, ?string $target_locale = null): string /** * @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 @@ -76,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 @@ -94,8 +93,8 @@ function locale_path($page, string $partial_path, ?string $target_locale = null) /** * @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 From b085b2d7bac7e2a965c70c788e5e61d05610c81c Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Wed, 3 Apr 2024 12:53:26 -0300 Subject: [PATCH 4/5] chore: Bump php version Signed-off-by: Vitor Mattos --- .github/workflows/phpstan.yml | 2 +- .github/workflows/run-tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 }} From 047abccb52ea5e7ec3c1fb036390700a1e9af54d Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Wed, 3 Apr 2024 12:58:42 -0300 Subject: [PATCH 5/5] chore: Bump Jigsaw to be compatible with php 8.3 Signed-off-by: Vitor Mattos --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": [