1 | <?php namespace Arcanedev\Localization\Bases; |
||
14 | abstract class Middleware extends BaseMiddleware |
||
15 | { |
||
16 | /* ------------------------------------------------------------------------------------------------ |
||
17 | | Properties |
||
18 | | ------------------------------------------------------------------------------------------------ |
||
19 | */ |
||
20 | /** |
||
21 | * The URIs that should not be localized. |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $except = []; |
||
26 | |||
27 | /* ------------------------------------------------------------------------------------------------ |
||
28 | | Getters & Setters |
||
29 | | ------------------------------------------------------------------------------------------------ |
||
30 | */ |
||
31 | /** |
||
32 | * Get the default locale. |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | 15 | public function getDefaultLocale() |
|
40 | |||
41 | /** |
||
42 | * Get the current locale. |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | 9 | public function getCurrentLocale() |
|
50 | |||
51 | /** |
||
52 | * Return an array of all supported Locales. |
||
53 | * |
||
54 | * @throws UndefinedSupportedLocalesException |
||
55 | * |
||
56 | * @return LocaleCollection |
||
57 | */ |
||
58 | 9 | public function getSupportedLocales() |
|
62 | |||
63 | /** |
||
64 | * Hide the default locale in URL ?? |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | 9 | protected function hideDefaultLocaleInURL() |
|
72 | |||
73 | /* ------------------------------------------------------------------------------------------------ |
||
74 | | Check Functions |
||
75 | | ------------------------------------------------------------------------------------------------ |
||
76 | */ |
||
77 | /** |
||
78 | * Check is default locale hidden. |
||
79 | * |
||
80 | * @param string|null $locale |
||
81 | * |
||
82 | * @return bool |
||
83 | */ |
||
84 | 6 | protected function isDefaultLocaleHidden($locale) |
|
88 | |||
89 | /** |
||
90 | * Determine if the request has a URI that should not be localized. |
||
91 | * |
||
92 | * @param \Illuminate\Http\Request $request |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | 15 | protected function shouldIgnore($request) |
|
97 | { |
||
98 | 15 | foreach ($this->except as $except) { |
|
99 | if ($except !== '/') |
||
100 | $except = trim($except, '/'); |
||
101 | |||
102 | if ($request->is($except)) |
||
103 | return true; |
||
104 | } |
||
105 | |||
106 | 15 | return false; |
|
107 | } |
||
108 | |||
109 | /* ------------------------------------------------------------------------------------------------ |
||
110 | | Other Functions |
||
111 | | ------------------------------------------------------------------------------------------------ |
||
112 | */ |
||
113 | /** |
||
114 | * Get the redirection response. |
||
115 | * |
||
116 | * @param string $locale |
||
117 | * |
||
118 | * @return RedirectResponse|null |
||
119 | */ |
||
120 | 6 | protected function getLocalizedRedirect($locale) |
|
128 | |||
129 | /** |
||
130 | * Make a redirect response. |
||
131 | * |
||
132 | * @param string $url |
||
133 | * @param int $code |
||
134 | * |
||
135 | * @return RedirectResponse |
||
136 | */ |
||
137 | 12 | protected function makeRedirectResponse($url, $code = 302) |
|
141 | } |
||
142 |