Skip to content

Commit 895a356

Browse files
The list of middlewares of the route group is moved to config
1 parent de94305 commit 895a356

File tree

9 files changed

+29
-30
lines changed

9 files changed

+29
-30
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"illuminate/http": "^10.0 || ^11.0 || ^12.0",
3434
"illuminate/routing": "^10.0 || ^11.0 || ^12.0",
3535
"illuminate/support": "^10.0 || ^11.0 || ^12.0",
36-
"laravel-lang/config": "^1.12",
36+
"laravel-lang/config": "^1.13",
3737
"laravel-lang/locales": "^2.10"
3838
},
3939
"require-dev": {

src/Events/LocaleHasBeenSetEvent.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ class LocaleHasBeenSetEvent
1616

1717
public function __construct(
1818
public LocaleData $locale
19-
) {
20-
}
19+
) {}
2120
}

src/Middlewares/LocalizationByModel.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class LocalizationByModel extends Middleware
1111
{
1212
public function __construct(
1313
protected ?string $guard = null,
14-
) {
15-
}
14+
) {}
1615

1716
protected function detect(Request $request): bool|float|int|string|null
1817
{

src/Services/Route.php

+16-18
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,33 @@
66

77
use Closure;
88
use Illuminate\Support\Facades\Route as BaseRoute;
9+
use LaravelLang\Config\Facades\Config;
910
use LaravelLang\Routes\Concerns\RouteParameters;
1011
use LaravelLang\Routes\Helpers\Route as RouteName;
11-
use LaravelLang\Routes\Middlewares\LocalizationByCookie;
12-
use LaravelLang\Routes\Middlewares\LocalizationByHeader;
13-
use LaravelLang\Routes\Middlewares\LocalizationByModel;
14-
use LaravelLang\Routes\Middlewares\LocalizationByParameterPrefix;
15-
use LaravelLang\Routes\Middlewares\LocalizationBySession;
1612

1713
class Route
1814
{
1915
use RouteParameters;
2016

2117
public function group(Closure $callback): void
2218
{
23-
BaseRoute::middleware([
24-
LocalizationByCookie::class,
25-
LocalizationByHeader::class,
26-
LocalizationBySession::class,
27-
LocalizationByModel::class,
28-
])->group($callback);
19+
$this->defaultGroup($callback);
20+
$this->prefixedGroup($callback);
21+
}
2922

23+
protected function defaultGroup(Closure $callback): void
24+
{
25+
BaseRoute::middleware(
26+
Config::shared()->routes->group->middleware->default
27+
)->group($callback);
28+
}
29+
30+
protected function prefixedGroup(Closure $callback): void
31+
{
3032
BaseRoute::prefix('{' . $this->names()->parameter . '}')
3133
->name(RouteName::prefix())
32-
->middleware([
33-
LocalizationByParameterPrefix::class,
34-
LocalizationByCookie::class,
35-
LocalizationByHeader::class,
36-
LocalizationBySession::class,
37-
LocalizationByModel::class,
38-
])->group($callback);
34+
->middleware(
35+
Config::shared()->routes->group->middleware->prefix
36+
)->group($callback);
3937
}
4038
}

tests/Constants/LocaleValue.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
class LocaleValue
88
{
9-
public const LocaleAlias = 'de-DE';
9+
public const LocaleAlias = 'de-DE';
1010
public const LocaleAliasParent = 'de';
11-
public const LocaleMain = 'fr';
11+
public const LocaleMain = 'fr';
1212
public const TranslationFrench = 'Toutes les données ont été chargées.';
1313
public const TranslationGerman = 'Alle Ressourcen geladen.';
14-
public const TranslationKey = 'Foo';
14+
public const TranslationKey = 'Foo';
1515
}

tests/Pest.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Illuminate\Foundation\Testing\DatabaseTransactions;
46
use Illuminate\Support\Facades\Event;
57

tests/TestCase.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Tests;
46

57
use Closure;

tests/Unit/Helpers/LocalizedRouteTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use Tests\Constants\LocaleValue;
77

88
test('route groups', function () {
9-
$name = Config::shared()->routes->namePrefix;
10-
$locale = LocaleValue::LocaleMain;
9+
$name = Config::shared()->routes->namePrefix;
10+
$locale = LocaleValue::LocaleMain;
1111
$fallback = LocaleValue::LocaleAliasParent;
1212

1313
expect(localizedRoute($name . 'via.group.facade', ['foo' => 'bar']))

tests/database/migrations/2024_06_20_000000_create_users_table.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
use Illuminate\Database\Schema\Blueprint;
77
use Illuminate\Support\Facades\Schema;
88

9-
return new class extends Migration
10-
{
9+
return new class extends Migration {
1110
public function up(): void
1211
{
1312
Schema::create('users', function (Blueprint $table) {

0 commit comments

Comments
 (0)