Skip to content

Commit 1f150ca

Browse files
committed
feat: add support for lingo on groups
1 parent 67cf923 commit 1f150ca

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Router.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class Router
6565
*/
6666
protected static $routeGroupMiddleware = [];
6767

68+
/**
69+
* Lingo options
70+
*/
71+
protected static $lingoOptions = [
72+
'lingo.no_locale_prefix' => false,
73+
'lingo.routes' => []
74+
];
75+
6876
/**
6977
* Current group base path
7078
*/
@@ -118,6 +126,7 @@ public static function mount(string $path, $handler)
118126

119127
$initialNamespace = static::$namespace;
120128
$initialGroupRoute = static::$groupRoute;
129+
$initialLingoOptioins = static::$lingoOptions;
121130
$initialGroupMiddleware = static::$routeGroupMiddleware;
122131

123132
if ($groupOptions['namespace']) {
@@ -130,10 +139,19 @@ public static function mount(string $path, $handler)
130139
static::$routeGroupMiddleware = $groupOptions['middleware'];
131140
}
132141

142+
if (isset($groupOptions['lingo.routes'])) {
143+
static::$lingoOptions['lingo.routes'] = $groupOptions['lingo.routes'];
144+
}
145+
146+
if (isset($groupOptions['lingo.no_locale_prefix'])) {
147+
static::$lingoOptions['lingo.no_locale_prefix'] = $groupOptions['lingo.no_locale_prefix'];
148+
}
149+
133150
call_user_func($handler);
134151

135152
static::$namespace = $initialNamespace;
136153
static::$groupRoute = $initialGroupRoute;
154+
static::$lingoOptions = $initialLingoOptioins;
137155
static::$routeGroupMiddleware = $initialGroupMiddleware;
138156
}
139157

@@ -183,8 +201,8 @@ public static function match(string $allowedMethods, string $pattern, $handler)
183201
'pattern' => $pattern,
184202
'handler' => $handler,
185203
'name' => $routeOptions['name'] ?? '',
186-
'lingo.routes' => $routeOptions['lingo.routes'] ?? [],
187-
'lingo.no_locale_prefix' => $routeOptions['lingo.no_locale_prefix'] ?? false,
204+
'lingo.routes' => $routeOptions['lingo.routes'] ?? static::$lingoOptions['lingo.routes'] ?? [],
205+
'lingo.no_locale_prefix' => $routeOptions['lingo.no_locale_prefix'] ?? static::$lingoOptions['lingo.no_locale_prefix'] ?? false,
188206
];
189207

190208
if ($routeOptions['middleware'] || !empty(static::$routeGroupMiddleware)) {

0 commit comments

Comments
 (0)