From e3563e5f66b30ffd09ff5507f5aaaacc69cc904b Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 14 Jun 2024 10:52:30 +0300 Subject: [PATCH] Adding route groups with a locale prefix --- src/Facades/LocalizationRoute.php | 20 +++++++++++ src/Services/Route.php | 34 +++++++++++++++++++ tests/Concerns/Routes.php | 8 +++++ tests/Feature/Facades/RouteTest.php | 10 ++++++ .../Feature/{ => Middlewares}/CookieTest.php | 0 .../Feature/{ => Middlewares}/HeaderTest.php | 0 .../ParameterRedirectTest.php | 0 .../{ => Middlewares}/ParameterTest.php | 0 .../Feature/{ => Middlewares}/SessionTest.php | 0 .../Feature/{ => Middlewares}/WithoutTest.php | 0 10 files changed, 72 insertions(+) create mode 100644 src/Facades/LocalizationRoute.php create mode 100644 src/Services/Route.php create mode 100644 tests/Feature/Facades/RouteTest.php rename tests/Feature/{ => Middlewares}/CookieTest.php (100%) rename tests/Feature/{ => Middlewares}/HeaderTest.php (100%) rename tests/Feature/{ => Middlewares}/ParameterRedirectTest.php (100%) rename tests/Feature/{ => Middlewares}/ParameterTest.php (100%) rename tests/Feature/{ => Middlewares}/SessionTest.php (100%) rename tests/Feature/{ => Middlewares}/WithoutTest.php (100%) diff --git a/src/Facades/LocalizationRoute.php b/src/Facades/LocalizationRoute.php new file mode 100644 index 0000000..37b53d1 --- /dev/null +++ b/src/Facades/LocalizationRoute.php @@ -0,0 +1,20 @@ +names()->parameter)) + ->name($this->names()->parameter . '.') + ->middleware(LocalizationByParameter::class) + ->group($callback); + + BaseRoute::middleware([ + LocalizationByCookie::class, + LocalizationByHeader::class, + LocalizationBySession::class, + ])->group($callback); + } +} diff --git a/tests/Concerns/Routes.php b/tests/Concerns/Routes.php index a252640..665d625 100644 --- a/tests/Concerns/Routes.php +++ b/tests/Concerns/Routes.php @@ -5,6 +5,7 @@ namespace Tests\Concerns; use Closure; +use LaravelLang\Routes\Facades\LocalizationRoute; use LaravelLang\Routes\Middlewares\LocalizationByCookie; use LaravelLang\Routes\Middlewares\LocalizationByHeader; use LaravelLang\Routes\Middlewares\LocalizationByParameter; @@ -63,6 +64,13 @@ public function setUpRoutes(): void ->get('clean/{foo}', $this->jsonResponse()) ->name('clean'); }); + + LocalizationRoute::group(function () { + app('router') + ->middleware('web') + ->get('grouped', $this->jsonResponse()) + ->name('via.group'); + }); } protected function jsonResponse(): Closure diff --git a/tests/Feature/Facades/RouteTest.php b/tests/Feature/Facades/RouteTest.php new file mode 100644 index 0000000..c291cc6 --- /dev/null +++ b/tests/Feature/Facades/RouteTest.php @@ -0,0 +1,10 @@ +has('via.group'))->toBeTrue(); + expect(app('router')->has(Name::parameter() . '.via.group'))->toBeTrue(); +}); diff --git a/tests/Feature/CookieTest.php b/tests/Feature/Middlewares/CookieTest.php similarity index 100% rename from tests/Feature/CookieTest.php rename to tests/Feature/Middlewares/CookieTest.php diff --git a/tests/Feature/HeaderTest.php b/tests/Feature/Middlewares/HeaderTest.php similarity index 100% rename from tests/Feature/HeaderTest.php rename to tests/Feature/Middlewares/HeaderTest.php diff --git a/tests/Feature/ParameterRedirectTest.php b/tests/Feature/Middlewares/ParameterRedirectTest.php similarity index 100% rename from tests/Feature/ParameterRedirectTest.php rename to tests/Feature/Middlewares/ParameterRedirectTest.php diff --git a/tests/Feature/ParameterTest.php b/tests/Feature/Middlewares/ParameterTest.php similarity index 100% rename from tests/Feature/ParameterTest.php rename to tests/Feature/Middlewares/ParameterTest.php diff --git a/tests/Feature/SessionTest.php b/tests/Feature/Middlewares/SessionTest.php similarity index 100% rename from tests/Feature/SessionTest.php rename to tests/Feature/Middlewares/SessionTest.php diff --git a/tests/Feature/WithoutTest.php b/tests/Feature/Middlewares/WithoutTest.php similarity index 100% rename from tests/Feature/WithoutTest.php rename to tests/Feature/Middlewares/WithoutTest.php