Skip to content

Commit

Permalink
Updating ignored redirection by URI or Route name
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Mar 5, 2020
1 parent e4654a6 commit 8f7f9a1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
8 changes: 2 additions & 6 deletions _docs/2-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
//
],
```
Expand Down
8 changes: 2 additions & 6 deletions config/localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@
],

/* -----------------------------------------------------------------
| Ignored URI/Routes from localization
| Ignored URI/Route from localization
| -----------------------------------------------------------------
*/

'ignored-uri' => [
//
],

'ignored-routes' => [
'ignored-redirection' => [
//
],

Expand Down
32 changes: 16 additions & 16 deletions src/Middleware/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
| -----------------------------------------------------------------
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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', [])
);
}
}

0 comments on commit 8f7f9a1

Please sign in to comment.