diff --git a/.github/workflows/composer-normalize.yml b/.github/workflows/composer-normalize.yml new file mode 100644 index 0000000..5b648e3 --- /dev/null +++ b/.github/workflows/composer-normalize.yml @@ -0,0 +1,21 @@ +name: normalize composer.json + +on: + push: + paths: + - "composer.json" + +jobs: + normalize: + runs-on: ubuntu-latest + steps: + - name: Git checkout + uses: actions/checkout@v2 + + - name: normalize composer.json + run: | + composer global require ergebnis/composer-normalize + composer normalize + - uses: stefanzweifel/git-auto-commit-action@v4.0.0 + with: + commit_message: normalize composer.json diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 28b0602..7694691 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -13,12 +13,14 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.0] - laravel: [8.*] + php: [8.1, 8.0] + laravel: [8.*, 9.*] stability: [prefer-lowest, prefer-stable] include: - laravel: 8.* - testbench: ^6.6 + testbench: ^6.23 + - laravel: 9.* + testbench: 7.* name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..fa56639 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,28 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +jobs: + update: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: main + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/composer.json b/composer.json index d130dae..5f2b202 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,12 @@ { "name": "cosnavel/laravel-query-localization", "description": "Query String Localization Package for Laravel", + "license": "MIT", "keywords": [ "Cosnavel", "laravel", "laravel-query-localization" ], - "homepage": "https://github.com/cosnavel/laravel-query-localization", - "license": "MIT", "authors": [ { "name": "Cosnavel", @@ -15,20 +14,26 @@ "role": "Developer" } ], + "homepage": "https://github.com/cosnavel/laravel-query-localization", "require": { "php": "^8.0", - "illuminate/contracts": "^8.37", - "spatie/laravel-package-tools": "^1.4.3", - "timacdonald/has-parameters": "^1.2" + "illuminate/contracts": "^8.73 || ^9.0", + "spatie/laravel-package-tools": "^1.11" }, "require-dev": { "brianium/paratest": "^6.2", - "nunomaduro/collision": "^5.3", - "orchestra/testbench": "^6.15", + "livewire/livewire": "^2.10", + "nunomaduro/collision": "^5.3 || ^6.1", + "orchestra/testbench": "^6.23 || ^7.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^9.3", "spatie/laravel-ray": "^1.23", "vimeo/psalm": "^4.8" }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "Cosnavel\\LaravelQueryLocalization\\": "src", @@ -40,24 +45,27 @@ "Cosnavel\\LaravelQueryLocalization\\Tests\\": "tests" } }, - "scripts": { - "psalm": "vendor/bin/psalm", - "test": "./vendor/bin/testbench package:test --parallel --no-coverage", - "test-coverage": "vendor/bin/phpunit --coverage-html coverage" - }, "config": { + "allow-plugins": { + "composer/package-versions-deprecated": true, + "phpstan/extension-installer": true + }, "sort-packages": true }, "extra": { "laravel": { - "providers": [ - "Cosnavel\\LaravelQueryLocalization\\LaravelQueryLocalizationServiceProvider" - ], "aliases": { "LaravelQueryLocalization": "Cosnavel\\LaravelQueryLocalization\\LaravelQueryLocalizationFacade" - } + }, + "providers": [ + "Cosnavel\\LaravelQueryLocalization\\LaravelQueryLocalizationServiceProvider" + ] } }, - "minimum-stability": "dev", - "prefer-stable": true + "scripts": { + "analyse": "vendor/bin/phpstan analyse", + "psalm": "vendor/bin/psalm", + "test": "./vendor/bin/testbench package:test --no-coverage", + "test-coverage": "vendor/bin/phpunit --coverage-html coverage" + } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..04408db --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,8 @@ +parameters: + level: 5 + paths: + - src + - config + - database + tmpDir: build/phpstan + checkMissingIterableValueType: false diff --git a/src/Macros/RouterMacros.php b/src/Macros/RouterMacros.php index 9d31a35..8391ff3 100644 --- a/src/Macros/RouterMacros.php +++ b/src/Macros/RouterMacros.php @@ -15,12 +15,11 @@ public function localize() $translationRoutes[$lang] = trans($routeTranslationKey, [], $lang); } + return $this->group([], function () use ($translationRoutes, $action, $routeName) { foreach ($translationRoutes as $language => $translatedRoute) { $this->group([ - 'prefix' => $translatedRoute, 'middleware' => LocaleFromQuery::with([ - 'translatedRoute' => $language, - ]), + 'prefix' => $translatedRoute, 'middleware' => LocaleFromQuery::class.":$language", ], function () use ($action, $routeName) { $this->get('/', $action)->name($routeName); }); diff --git a/src/Middleware/LocaleFromQuery.php b/src/Middleware/LocaleFromQuery.php index b5128c3..3ec1e87 100644 --- a/src/Middleware/LocaleFromQuery.php +++ b/src/Middleware/LocaleFromQuery.php @@ -5,12 +5,9 @@ use Closure; use Cosnavel\LaravelQueryLocalization\Facades\LaravelQueryLocalization; use Illuminate\Http\Request; -use TiMacDonald\Middleware\HasParameters; class LocaleFromQuery { - use HasParameters; - public function handle(Request $request, Closure $next, string $translatedRoute = null) { if ($request->get('locale')) { diff --git a/tests/TestCase.php b/tests/TestCase.php index e0287c5..ac2a901 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,6 +4,7 @@ use Cosnavel\LaravelQueryLocalization\LaravelQueryLocalizationServiceProvider; use Illuminate\Database\Eloquent\Factories\Factory; +use Livewire\LivewireServiceProvider; use Orchestra\Testbench\TestCase as Orchestra; abstract class TestCase extends Orchestra @@ -27,6 +28,7 @@ public function setUp(): void protected function getPackageProviders($app) { return [ + LivewireServiceProvider::class, LaravelQueryLocalizationServiceProvider::class, ]; } @@ -44,10 +46,5 @@ public function getEnvironmentSetUp($app) 'query-localization.useAcceptLanguageHeader' => true, 'query-localization.useUserLanguagePreference' => true, ]); - - /* - include_once __DIR__.'/../database/migrations/create_laravel-query-localization_table.php.stub'; - (new \CreatePackageTable())->up(); - */ } }