1 | <?php |
||
20 | class LanguageMiddleware |
||
21 | { |
||
22 | use TranslatorAwareTrait; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $defaultLanguage; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | private $browserLanguage; |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private $excludedPath; |
||
38 | |||
39 | /** |
||
40 | * @var boolean |
||
41 | */ |
||
42 | private $usePath; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | private $pathRegexp; |
||
48 | |||
49 | /** |
||
50 | * @var boolean |
||
51 | */ |
||
52 | private $useBrowser; |
||
53 | |||
54 | /** |
||
55 | * @var boolean |
||
56 | */ |
||
57 | private $useSession; |
||
58 | |||
59 | /** |
||
60 | * @var string[] |
||
61 | */ |
||
62 | private $sessionKey; |
||
63 | |||
64 | /** |
||
65 | * @var boolean |
||
66 | */ |
||
67 | private $useParams; |
||
68 | |||
69 | /** |
||
70 | * @var string[] |
||
71 | */ |
||
72 | private $paramKey; |
||
73 | |||
74 | /** |
||
75 | * @param array $data The middleware options. |
||
76 | */ |
||
77 | public function __construct(array $data) |
||
123 | |||
124 | /** |
||
125 | * @param RequestInterface $request The PSR-7 HTTP request. |
||
126 | * @param ResponseInterface $response The PSR-7 HTTP response. |
||
127 | * @param callable $next The next middleware callable in the stack. |
||
128 | * @return ResponseInterface |
||
129 | */ |
||
130 | public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next) |
||
146 | |||
147 | /** |
||
148 | * @param RequestInterface $request The PSR-7 HTTP request. |
||
149 | * @return null|string |
||
150 | */ |
||
151 | private function getLanguage(RequestInterface $request) |
||
183 | |||
184 | /** |
||
185 | * @param RequestInterface $request The PSR-7 HTTP request. |
||
186 | * @return null|string |
||
187 | */ |
||
188 | private function getLanguageFromPath(RequestInterface $request) |
||
203 | |||
204 | /** |
||
205 | * @param RequestInterface $request The PSR-7 HTTP request. |
||
206 | * @return string |
||
207 | */ |
||
208 | private function getLanguageFromParams(RequestInterface $request) |
||
222 | |||
223 | /** |
||
224 | * @return string |
||
225 | */ |
||
226 | private function getLanguageFromSession() |
||
237 | |||
238 | /** |
||
239 | * @return mixed |
||
240 | */ |
||
241 | private function getLanguageFromBrowser() |
||
245 | |||
246 | /** |
||
247 | * @param string $lang The language code to set. |
||
248 | * @return void |
||
249 | */ |
||
250 | private function setLanguage($lang) |
||
264 | |||
265 | /** |
||
266 | * @param string $lang The language code to set. |
||
267 | * @return void |
||
268 | */ |
||
269 | private function setLocale($lang) |
||
297 | } |
||
298 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: