1 | <?php |
||
11 | class MultilingualRegistrar |
||
12 | { |
||
13 | /** |
||
14 | * The router instance. |
||
15 | * |
||
16 | * @var \Illuminate\Routing\Router |
||
17 | */ |
||
18 | protected $router; |
||
19 | |||
20 | /** |
||
21 | * Constructor of the class. |
||
22 | * |
||
23 | * @param \Illuminate\Routing\Router $router |
||
24 | */ |
||
25 | public function __construct(Router $router) |
||
29 | |||
30 | /** |
||
31 | * Register the routes. |
||
32 | * |
||
33 | * @param string $key |
||
34 | * @param mixed $handle |
||
35 | * @param array $locales |
||
36 | * @param array $options |
||
37 | * @return \Illuminate\Routing\RouteCollection |
||
38 | */ |
||
39 | public function register(string $key, $handle, array $locales, array $options): RouteCollection |
||
53 | |||
54 | /** |
||
55 | * Register a single route. |
||
56 | * |
||
57 | * @param string $key |
||
58 | * @param mixed $handle |
||
59 | * @param string $locale |
||
60 | * @param array $options |
||
61 | * @return \Illuminate\Routing\Route |
||
62 | */ |
||
63 | protected function registerRoute(string $key, $handle, string $locale, array $options): Route |
||
90 | |||
91 | /** |
||
92 | * Generate a route. |
||
93 | * |
||
94 | * @param string $key |
||
95 | * @param mixed $handle |
||
96 | * @param string $locale |
||
97 | * @param array $options |
||
98 | * @return \Illuminate\Routing\Route |
||
99 | */ |
||
100 | protected function generateRoute(string $key, $handle, string $locale, array $options): Route |
||
119 | |||
120 | /** |
||
121 | * Retrieve the request method from the options. |
||
122 | * |
||
123 | * @param array $options |
||
124 | * @return array |
||
125 | */ |
||
126 | protected function getRequestMethodFromOptions(array $options): array |
||
136 | |||
137 | /** |
||
138 | * Generate the name of the route based on the options. |
||
139 | * |
||
140 | * @param string $locale |
||
141 | * @param string $key |
||
142 | * @param array $options |
||
143 | * @return string |
||
144 | */ |
||
145 | protected function generateNameForLocaleFromOptions(string $locale, string $key, array $options): string |
||
157 | |||
158 | /** |
||
159 | * Generate the prefix of the route based on the options. |
||
160 | * |
||
161 | * @param string $key |
||
162 | * @param string $locale |
||
163 | * @return string|null |
||
164 | */ |
||
165 | protected function generatePrefixForLocale(string $key, string $locale): ?string |
||
173 | |||
174 | /** |
||
175 | * Generate the route uri from the translation key and locale. |
||
176 | * |
||
177 | * @param string $key |
||
178 | * @param string $locale |
||
179 | * @return string |
||
180 | */ |
||
181 | protected function generateUriFromKey(string $key, string $locale): string |
||
191 | |||
192 | /** |
||
193 | * Apply the unique registration key to make sure the route is registered. |
||
194 | * |
||
195 | * @param string $uri |
||
196 | * @param string $locale |
||
197 | * @return string |
||
198 | */ |
||
199 | protected function applyUniqueRegistrationKey(string $uri, string $locale): string |
||
203 | |||
204 | /** |
||
205 | * Clean the unique registration key from the route uri after it has been |
||
206 | * registered in the router. |
||
207 | * |
||
208 | * @param \Illuminate\Routing\Route $route |
||
209 | * @param string $locale |
||
210 | * @return \Illuminate\Routing\Route |
||
211 | */ |
||
212 | protected function cleanUniqueRegistrationKey(Route $route, string $locale): Route |
||
216 | |||
217 | /** |
||
218 | * Verify if we should not prefix the locale. |
||
219 | * |
||
220 | * @param string $locale |
||
221 | * @return bool |
||
222 | */ |
||
223 | protected function shouldNotPrefixLocale(string $locale): bool |
||
228 | |||
229 | /** |
||
230 | * Verify if we should not prefix the home page. |
||
231 | * |
||
232 | * @param string $locale |
||
233 | * @return bool |
||
234 | */ |
||
235 | protected function shouldNotPrefixHome(string $locale): bool |
||
240 | |||
241 | /** |
||
242 | * Verify if we should not prefix the home page. |
||
243 | * |
||
244 | * @param string $locale |
||
245 | * @return bool |
||
246 | */ |
||
247 | protected function shouldNotPrefixDefaultHome(string $locale): bool |
||
252 | |||
253 | /** |
||
254 | * Apply the constraints of a route. |
||
255 | * |
||
256 | * @param \Illuminate\Routing\Route $route |
||
257 | * @param string $locale |
||
258 | * @param array $options |
||
259 | * @return void |
||
260 | */ |
||
261 | protected function applyConstraints(Route $route, string $locale, $options): void |
||
272 | } |
||
273 |