Skip to content

Commit d2c7dfe

Browse files
Merge pull request #153 from ARCANEDEV/update-2
Updating the last changes
2 parents 28331ec + c317e2e commit d2c7dfe

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

_docs/2-Configuration.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
2. [Configuration](2-Configuration.md)
77
3. [Usage](3-Usage.md)
88
4. [FAQ](4-FAQ.md)
9-
9+
1010
## Settings
1111

1212
```php
@@ -66,15 +66,19 @@ return [
6666
| localized-routes | Allows to register all translatable routes. |
6767
| translation-redirect | Allows to translate the route attributes by using the translation event. |
6868

69-
## Ignored URI
69+
## Ignored URI / Route
7070

7171
```php
7272
'ignored-uri' => [
7373
//
7474
],
75+
76+
'ignored-routes' => [
77+
//
78+
],
7579
```
7680

77-
You can set a list of uris to ignore from localization checks.
81+
You can set a list of uris or route names to ignore from localization checks / redirection.
7882

7983
## Locales
8084

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"ext-intl": "*",
2323
"orchestra/testbench": "^4.0",
2424
"mockery/mockery": "^1.3.1",
25-
"phpunit/phpcov": "^6.0",
2625
"phpunit/phpunit": "^8.0"
2726
},
2827
"autoload": {

config/localization.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,14 @@
3333
],
3434

3535
/* -----------------------------------------------------------------
36-
| Ignored URI from localization
36+
| Ignored URI/Routes from localization
3737
| -----------------------------------------------------------------
3838
*/
3939

4040
'ignored-uri' => [
4141
//
4242
],
4343

44-
/* -----------------------------------------------------------------
45-
| Ignored routes from localization
46-
| -----------------------------------------------------------------
47-
*/
4844
'ignored-routes' => [
4945
//
5046
],

src/Middleware/Middleware.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,12 @@ abstract class Middleware
2929
protected $localization;
3030

3131
/**
32-
* The URIs that should not be localized.
32+
* The URIs or route names that should not be localized.
3333
*
3434
* @var array
3535
*/
3636
protected $except = [];
3737

38-
/**
39-
* The routes that should not be localized.
40-
*
41-
* @var array
42-
*/
43-
protected $except_routes = [];
44-
4538
/* -----------------------------------------------------------------
4639
| Constructor
4740
| -----------------------------------------------------------------
@@ -54,9 +47,8 @@ abstract class Middleware
5447
*/
5548
public function __construct(Localization $localization)
5649
{
57-
$this->localization = $localization;
58-
$this->except = config('localization.ignored-uri', []);
59-
$this->except_routes = config('localization.ignored-routes', []);
50+
$this->localization = $localization;
51+
$this->except = $this->getIgnoredRedirection();
6052
}
6153

6254
/* -----------------------------------------------------------------
@@ -127,17 +119,15 @@ protected function isDefaultLocaleHidden($locale)
127119
*
128120
* @return bool
129121
*/
130-
protected function shouldIgnore(Request $request)
122+
protected function shouldIgnore(Request $request): bool
131123
{
132124
foreach ($this->except as $except) {
133125
if ($except !== '/')
134126
$except = trim($except, '/');
135127

136128
if ($request->is($except))
137129
return true;
138-
}
139130

140-
foreach ($this->except_routes as $except) {
141131
if ($request->routeIs($except))
142132
return true;
143133
}
@@ -176,4 +166,17 @@ protected function makeRedirectResponse($url, $code = null)
176166
{
177167
return new RedirectResponse($url, $code ?? config('localization.redirection-code', 302), ['Vary' => 'Accept-Language']);
178168
}
169+
170+
/**
171+
* The URIs or route names that should not be redirected.
172+
*
173+
* @return array
174+
*/
175+
protected function getIgnoredRedirection(): array
176+
{
177+
return array_merge(
178+
config('localization.ignored-uri', []),
179+
config('localization.ignored-routes', [])
180+
);
181+
}
179182
}

tests/fixtures/migrations/2017_06_01_000000_create_translatable_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CreateTranslatableTable extends Migration
2929
/**
3030
* Migrate to database.
3131
*/
32-
public function up()
32+
public function up(): void
3333
{
3434
$this->createSchema(function (Blueprint $table) {
3535
$table->increments('id');

0 commit comments

Comments
 (0)