$control = array_shift($uri_parts); // alias контроллера if (count($uri_parts) >= 1) { $action = array_shift($uri_parts); // alias action } } $ctrl = '\\App\\Controllers\\' . $control; if (!class_exists($ctrl)) { $e = new \App\Exceptions\Err404('Неверный адрес '); $e->setExtParams(['uri' => $_SERVER['REQUEST_URI'], 'ctrl' => $ctrl]); throw $e; } $controller = new $ctrl(); if (!method_exists($controller, 'action' . $action)) { $e = new \App\Exceptions\Err404('Несуществующий адрес '); $e->setExtParams(['uri' => $_SERVER['REQUEST_URI'], 'ctrl' => $ctrl, 'act' => $action]); throw $e; } $controller->action($action); } catch (\App\Exceptions\DB $e) { $err = new \App\Controllers\Error(); $err->actionDbError($e->getMessage()); $logger = new \App\LogUseLib(); $logger->emergency($e->getMessage(), $e->getMess()); } catch (\App\Exceptions\Err404 $e) { $err = new \App\Controllers\Error(); $err->action404($e->getMessage()); $logger = new \App\LogUseLib(); $logger->alert($e->getMessage(), $e->getMess()); }
} } if (empty($params[0])) { $params[0] = 'article'; } $action = isset($params[1]) ? $params[1] : 'index'; switch ($params[0]) { case 'article': $controller = new \App\Controllers\Article(); break; case 'admin': $controller = new \App\Controllers\Admin(); break; default: $controller = new \App\Controllers\Error(); $action = 'error404'; Logger::instance()->save('Ошибка 404: Введен не существующий адресс'); } try { $controller->action($action); exit; } catch (\App\Exception\DB $e) { $action = 'DBError'; \App\Mailer::instance()->send('Ошибка подключения к БД'); } catch (\App\Exception\Error404 $e) { $action = 'error404'; } finally { $controller = new \App\Controllers\Error(); $controller->action($action); Logger::instance()->save($e->getMessage()); }
$ctrl = !empty($pathRev[0]) ? 'App\\Controllers\\' . $pathRev[0] : 'App\\Controllers\\News'; $action = 'Index'; break; case 3: $ctrl = !empty($pathRev[1]) ? 'App\\Controllers\\' . $pathRev[1] : 'App\\Controllers\\News'; $action = !empty($pathRev[0]) ? $pathRev[0] : 'Index'; break; default: $ctrl = !empty($pathRev[2]) ? 'App\\Controllers\\' . $pathRev[2] : 'App\\Controllers\\News'; $action = !empty($pathRev[1]) ? $pathRev[1] : 'Index'; break; } try { $controller = new $ctrl(); if (!method_exists($controller, 'action' . $action)) { throw new \App\Exceptions\Error404(); } $controller->action($action); } catch (\App\Exceptions\Error404 $e) { $error = new \App\Controllers\Error(); $error->action404(); } catch (\App\Exceptions\Core $e) { echo 'Возникло исключение ' . $e->getMessage(); } catch (\App\Exceptions\Db $e) { $error = new \App\Controllers\Error(); $error->error($e->getMessage()); // echo 'Что-то не так с базой ' . $e->getMessage(); } catch (\App\MultiException $e) { $error = new \App\Controllers\Error(); $error->errorForm($e); }