Initial commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
namespace app\middleware;
|
||||
|
||||
use Webman\MiddlewareInterface;
|
||||
use Webman\Http\Response;
|
||||
use Webman\Http\Request;
|
||||
|
||||
class Lang implements MiddlewareInterface
|
||||
{
|
||||
public function process(Request $request, callable $handler) : Response
|
||||
{
|
||||
$lang = $request->header('Lang');
|
||||
|
||||
if ($lang === NULL) {
|
||||
$body = [
|
||||
'status' => 'error',
|
||||
'code' => 403,
|
||||
'message' => 'Please bring your language.',
|
||||
'data' => [],
|
||||
];
|
||||
return response(json_encode($body, JSON_UNESCAPED_UNICODE), 403, ['Content-Type' => 'application/json']);
|
||||
}
|
||||
|
||||
if ($lang) {
|
||||
locale($lang);
|
||||
} else {
|
||||
locale('zh_CN');
|
||||
}
|
||||
|
||||
return $handler($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user