From 8f7f9a1139acf48e043a736968c53471c1f540eb Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Thu, 5 Mar 2020 10:11:23 +0100 Subject: [PATCH] Updating ignored redirection by URI or Route name --- _docs/2-Configuration.md | 8 ++------ config/localization.php | 8 ++------ src/Middleware/Middleware.php | 32 ++++++++++++++++---------------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/_docs/2-Configuration.md b/_docs/2-Configuration.md index 5ad145f..b43d4e5 100644 --- a/_docs/2-Configuration.md +++ b/_docs/2-Configuration.md @@ -66,14 +66,10 @@ return [ | localized-routes | Allows to register all translatable routes. | | translation-redirect | Allows to translate the route attributes by using the translation event. | -## Ignored URI / Route +## Ignored URI/Route from localization ```php - 'ignored-uri' => [ - // - ], - - 'ignored-routes' => [ + 'ignored-redirection' => [ // ], ``` diff --git a/config/localization.php b/config/localization.php index f68daa0..ff3cd50 100644 --- a/config/localization.php +++ b/config/localization.php @@ -33,15 +33,11 @@ ], /* ----------------------------------------------------------------- - | Ignored URI/Routes from localization + | Ignored URI/Route from localization | ----------------------------------------------------------------- */ - 'ignored-uri' => [ - // - ], - - 'ignored-routes' => [ + 'ignored-redirection' => [ // ], diff --git a/src/Middleware/Middleware.php b/src/Middleware/Middleware.php index 9bc3a7a..e655443 100644 --- a/src/Middleware/Middleware.php +++ b/src/Middleware/Middleware.php @@ -95,6 +95,16 @@ protected function hideDefaultLocaleInURL() return $this->localization->isDefaultLocaleHiddenInUrl(); } + /** + * Get the ignored URI/Route. + * + * @return array + */ + protected function getIgnoredRedirection(): array + { + return config('localization.ignored-redirection', []); + } + /* ----------------------------------------------------------------- | Check Methods | ----------------------------------------------------------------- @@ -122,14 +132,17 @@ protected function isDefaultLocaleHidden($locale) protected function shouldIgnore(Request $request): bool { foreach ($this->except as $except) { - if ($except !== '/') + if ($except !== '/') { $except = trim($except, '/'); + } - if ($request->is($except)) + if ($request->is($except)) { return true; + } - if ($request->routeIs($except)) + if ($request->routeIs($except)) { return true; + } } return false; @@ -166,17 +179,4 @@ protected function makeRedirectResponse($url, $code = null) { return new RedirectResponse($url, $code ?? config('localization.redirection-code', 302), ['Vary' => 'Accept-Language']); } - - /** - * The URIs or route names that should not be redirected. - * - * @return array - */ - protected function getIgnoredRedirection(): array - { - return array_merge( - config('localization.ignored-uri', []), - config('localization.ignored-routes', []) - ); - } }