Conditions | 3 |
Paths | 4 |
Total Lines | 29 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
35 | public function handle($request, Closure $next) |
||
36 | { |
||
37 | // read the language from the request header |
||
38 | $locale = $request->header('Content-Language'); |
||
39 | |||
40 | // if the header is missed |
||
41 | if(!$locale){ |
||
42 | // take the default local language |
||
43 | $locale = $this->app->config->get('app.locale'); |
||
44 | } |
||
45 | |||
46 | // check the languages defined is supported |
||
47 | if (!array_key_exists($locale, $this->app->config->get('hello.supported_languages'))) { |
||
48 | // respond with error |
||
49 | return abort(403, 'Language not supported.'); |
||
50 | } |
||
51 | |||
52 | // set the local language |
||
53 | $this->app->setLocale($locale); |
||
54 | |||
55 | // get the response after the request is done |
||
56 | $response = $next($request); |
||
57 | |||
58 | // set Content Languages header in the response |
||
59 | $response->headers->set('Content-Language', $locale); |
||
60 | |||
61 | // return the response |
||
62 | return $response; |
||
63 | } |
||
64 | } |
||
65 |
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: