本文整理汇总了PHP中Symfony\Component\HttpKernel\HttpKernelInterface::setRouteMatch方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpKernelInterface::setRouteMatch方法的具体用法?PHP HttpKernelInterface::setRouteMatch怎么用?PHP HttpKernelInterface::setRouteMatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\HttpKernelInterface
的用法示例。
在下文中一共展示了HttpKernelInterface::setRouteMatch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
$match = $this->router->match($request->getPathInfo());
$route = substr($request->getPathInfo(), strlen(rtrim($this->config['baseDir'], '/')));
if ($match) {
$tokenValid = false;
$jwtCookie = $this->config['jwt']['cookieName'];
$jwtKey = $this->config['jwt']['key'];
// check token from cookie
if ($request->cookies->has($jwtCookie)) {
$jwt = $request->cookies->get($jwtCookie);
try {
$decoded = JWT::decode($jwt, $jwtKey, ['HS256']);
if ($decoded->e > time()) {
$tokenValid = true;
$this->auth->init($decoded->uid);
}
} catch (\Exception $e) {
$tokenValid = false;
if (!$catch) {
throw $e;
}
$response = $this->dispatcher->dispatch('Home#error', ['message' => '[' . $e->getCode() . '] ' . $e->getMessage() . '<pre>' . $e->getTraceAsString() . '</pre>']);
$response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
return $response;
}
}
$allowed = false;
$isPublic = false;
foreach ($this->config['publicArea'] as $publicRoute) {
if (preg_match('/^' . addcslashes($publicRoute, '/') . '/', $route)) {
$isPublic = true;
break;
}
}
if ($match['name'] == 'home') {
$isPublic = true;
}
if ($isPublic) {
if ($route == '/login' && $tokenValid) {
return new RedirectResponse($this->router->generate('dashboard'));
}
$allowed = true;
} else {
$allowed = $tokenValid;
}
if ($allowed) {
$this->app->setRouteMatch($match);
return $this->app->handle($request, $type, $catch);
} else {
$this->flash->warning('Sesi Anda telah habis atau Anda tidak berhak mengakses halaman ini, silakan login terlebih dahulu!');
$response = $this->dispatcher->dispatch('User#login', []);
$response->setStatusCode(Response::HTTP_UNAUTHORIZED);
return $response;
}
}
$response = $this->dispatcher->dispatch('Home#error', ['message' => 'Halaman tidak ditemukan: ' . $route]);
$response->setStatusCode(Response::HTTP_NOT_FOUND);
return $response;
}