-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding route groups with a locale prefix
- Loading branch information
1 parent
5e54e0b
commit e3563e5
Showing
10 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelLang\Routes\Facades; | ||
|
||
use Closure; | ||
use Illuminate\Support\Facades\Facade; | ||
use LaravelLang\Routes\Services\Route; | ||
|
||
/** | ||
* @method static void group(Closure $callback) | ||
*/ | ||
class LocalizationRoute extends Facade | ||
{ | ||
protected static function getFacadeAccessor(): string | ||
{ | ||
return Route::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelLang\Routes\Services; | ||
|
||
use Closure; | ||
use Illuminate\Support\Facades\Route as BaseRoute; | ||
use LaravelLang\Routes\Concerns\KeyNames; | ||
use LaravelLang\Routes\Middlewares\LocalizationByCookie; | ||
use LaravelLang\Routes\Middlewares\LocalizationByHeader; | ||
use LaravelLang\Routes\Middlewares\LocalizationByParameter; | ||
use LaravelLang\Routes\Middlewares\LocalizationBySession; | ||
|
||
use function sprintf; | ||
|
||
class Route | ||
{ | ||
use KeyNames; | ||
|
||
public function group(Closure $callback): void | ||
{ | ||
BaseRoute::prefix(sprintf('{%s}', $this->names()->parameter)) | ||
->name($this->names()->parameter . '.') | ||
->middleware(LocalizationByParameter::class) | ||
->group($callback); | ||
|
||
BaseRoute::middleware([ | ||
LocalizationByCookie::class, | ||
LocalizationByHeader::class, | ||
LocalizationBySession::class, | ||
])->group($callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use LaravelLang\Routes\Helpers\Name; | ||
|
||
test('group', function () { | ||
expect(app('router')->has('via.group'))->toBeTrue(); | ||
expect(app('router')->has(Name::parameter() . '.via.group'))->toBeTrue(); | ||
}); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.