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 |
||
88 | |||
89 | /** |
||
90 | * Generate a route. |
||
91 | * |
||
92 | * @param string $key |
||
93 | * @param mixed $handle |
||
94 | * @param string $locale |
||
95 | * @param array $options |
||
96 | * @return \Illuminate\Routing\Route |
||
97 | */ |
||
98 | protected function generateRoute(string $key, $handle, string $locale, array $options): Route |
||
117 | |||
118 | /** |
||
119 | * Retrieve the request method from the options. |
||
120 | * |
||
121 | * @param array $options |
||
122 | * @return array |
||
123 | */ |
||
124 | protected function getRequestMethodFromOptions(array $options): array |
||
134 | |||
135 | /** |
||
136 | * Generate the name of the route based on the options. |
||
137 | * |
||
138 | * @param string $locale |
||
139 | * @param string $key |
||
140 | * @param array $options |
||
141 | * @return string |
||
142 | */ |
||
143 | protected function generateNameForLocaleFromOptions(string $locale, string $key, array $options): string |
||
155 | |||
156 | /** |
||
157 | * Generate the prefix of the route based on the options. |
||
158 | * |
||
159 | * @param string $key |
||
160 | * @param string $locale |
||
161 | * @return string|null |
||
162 | */ |
||
163 | protected function generatePrefixForLocale(string $key, string $locale): ?string |
||
171 | |||
172 | /** |
||
173 | * Generate the route uri from the translation key and locale. |
||
174 | * |
||
175 | * @param string $key |
||
176 | * @param string $locale |
||
177 | * @return string |
||
178 | */ |
||
179 | protected function generateUriFromKey(string $key, string $locale): string |
||
190 | |||
191 | /** |
||
192 | * Apply the unique registration key to make sure the route is registered. |
||
193 | * |
||
194 | * @param string $uri |
||
195 | * @param string $locale |
||
196 | * @return string |
||
197 | */ |
||
198 | protected function applyUniqueRegistrationKey(string $uri, string $locale): string |
||
202 | |||
203 | /** |
||
204 | * Clean the unique registration key from the route uri after it has been |
||
205 | * registered in the router. |
||
206 | * |
||
207 | * @param \Illuminate\Routing\Route $route |
||
208 | * @param string $locale |
||
209 | * @return \Illuminate\Routing\Route |
||
210 | */ |
||
211 | protected function cleanUniqueRegistrationKey(Route $route, string $locale): Route |
||
215 | |||
216 | /** |
||
217 | * Verify if we should not prefix the locale. |
||
218 | * |
||
219 | * @param string $locale |
||
220 | * @return bool |
||
221 | */ |
||
222 | protected function shouldNotPrefixLocale(string $locale): bool |
||
227 | |||
228 | /** |
||
229 | * Verify if we should not prefix the default Home Route. |
||
230 | * |
||
231 | * @param string $locale |
||
232 | * @return bool |
||
233 | */ |
||
234 | protected function shouldNotPrefixDefaultHome(string $locale): bool |
||
239 | } |
||
240 |