1 | <?php |
||
17 | abstract class Middleware |
||
18 | { |
||
19 | /* ----------------------------------------------------------------- |
||
20 | | Properties |
||
21 | | ----------------------------------------------------------------- |
||
22 | */ |
||
23 | |||
24 | /** |
||
25 | * The localization instance. |
||
26 | * |
||
27 | * @var \Arcanedev\Localization\Contracts\Localization |
||
28 | */ |
||
29 | protected $localization; |
||
30 | |||
31 | /** |
||
32 | * The URIs or route names that should not be localized. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $except = []; |
||
37 | |||
38 | /* ----------------------------------------------------------------- |
||
39 | | Constructor |
||
40 | | ----------------------------------------------------------------- |
||
41 | */ |
||
42 | |||
43 | /** |
||
44 | * Middleware constructor. |
||
45 | * |
||
46 | * @param \Arcanedev\Localization\Contracts\Localization $localization |
||
47 | */ |
||
48 | 30 | public function __construct(Localization $localization) |
|
49 | { |
||
50 | 30 | $this->localization = $localization; |
|
51 | 30 | $this->except = $this->getIgnoredRedirection(); |
|
52 | 30 | } |
|
53 | |||
54 | /* ----------------------------------------------------------------- |
||
55 | | Getters & Setters |
||
56 | | ----------------------------------------------------------------- |
||
57 | */ |
||
58 | /** |
||
59 | * Get the default locale. |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | 30 | public function getDefaultLocale() |
|
64 | { |
||
65 | 30 | return $this->localization->getDefaultLocale(); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * Get the current locale. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | 18 | public function getCurrentLocale() |
|
74 | { |
||
75 | 18 | return $this->localization->getCurrentLocale(); |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Return an array of all supported Locales. |
||
80 | * |
||
81 | * @return \Arcanedev\Localization\Entities\LocaleCollection |
||
82 | */ |
||
83 | 18 | public function getSupportedLocales() |
|
87 | |||
88 | /** |
||
89 | * Hide the default locale in URL ?? |
||
90 | * |
||
91 | * @return bool |
||
92 | */ |
||
93 | 18 | protected function hideDefaultLocaleInURL() |
|
97 | |||
98 | /* ----------------------------------------------------------------- |
||
99 | | Check Methods |
||
100 | | ----------------------------------------------------------------- |
||
101 | */ |
||
102 | |||
103 | /** |
||
104 | * Check is default locale hidden. |
||
105 | * |
||
106 | * @param string|null $locale |
||
107 | * |
||
108 | * @return bool |
||
109 | */ |
||
110 | 12 | protected function isDefaultLocaleHidden($locale) |
|
114 | |||
115 | /** |
||
116 | * Determine if the request has a URI that should not be localized. |
||
117 | * |
||
118 | * @param \Illuminate\Http\Request $request |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | 30 | protected function shouldIgnore(Request $request): bool |
|
137 | |||
138 | /* ----------------------------------------------------------------- |
||
139 | | Other Methods |
||
140 | | ----------------------------------------------------------------- |
||
141 | */ |
||
142 | |||
143 | /** |
||
144 | * Get the redirection response. |
||
145 | * |
||
146 | * @param string $locale |
||
147 | * |
||
148 | * @return \Illuminate\Http\RedirectResponse|null |
||
149 | */ |
||
150 | 12 | protected function getLocalizedRedirect($locale) |
|
156 | |||
157 | /** |
||
158 | * Make a redirect response. |
||
159 | * |
||
160 | * @param string $url |
||
161 | * @param int|null $code |
||
162 | * |
||
163 | * @return \Illuminate\Http\RedirectResponse |
||
164 | */ |
||
165 | 24 | protected function makeRedirectResponse($url, $code = null) |
|
169 | |||
170 | /** |
||
171 | * The URIs or route names that should not be redirected. |
||
172 | * |
||
173 | * @return array |
||
174 | */ |
||
175 | 30 | protected function getIgnoredRedirection(): array |
|
182 | } |
||
183 |