/** * Class constructor * * Initialize view and database classes. * * @return void */ public function __construct() { $this->view = new View(); $this->response = Response::getSoul(); $this->request = Request::getSoul(); $this->route = Route::getSoul(); $this->db = $this->db(); $this->model = ModelProvider::getSoul(); $this->config = Config::getSoul(); $this->cache = Cache::getSoul(); Hook::listen(__CLASS__); }
/** * General Error Page * * Takes an error message as input * and displays it using the specified template. * * @param string $message Error Message * @param int $code HTTP Header code * * @return void */ public static function halt($message, $code = 404) { Response::getSoul()->setStatus($code); if (Config::getSoul()->APP_DEBUG == false) { $message = '404 Not Found.'; } $tplPath = Config::getSoul()->ERROR_TPL; if ($tplPath == null || !Helper::isFile(Config::getSoul()->APP_FULL_PATH . '/views/' . $tplPath . '.html')) { $tpl = '<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Kotori.php 500 Internal Error</title> <meta name="robots" content="NONE,NOARCHIVE"> <style type="text/css"> html * { padding:0; margin:0; } body * { padding:10px 20px; } body * * { padding:0; } body { font:small sans-serif; background:#eee; } body>div { border-bottom:1px solid #ddd; } h1 { font-weight:normal; margin-bottom:.4em; } h1 span { font-size:60%; color:#666; font-weight:normal; } table { border:none; border-collapse: collapse; width:100%; } td, th { vertical-align:top; padding:2px 3px; } th { width:12em; text-align:right; color:#666; padding-right:.5em; } #info { background:#f6f6f6; } #info p {font-size: 16px} #summary { background: #ffc; } #explanation { background:#eee; border-bottom: 0px none; } </style> </head> <body> <div id="summary"> <h1>Kotori.php Internal Error <span>(500)</span></h1> <table class="meta"> <tr> <th>Request Method:</th> <td>' . strtoupper($_SERVER['REQUEST_METHOD']) . '</td> </tr> <tr> <th>Request URL:</th> <td>' . Request::getSoul()->getBaseUrl() . ltrim($_SERVER['REQUEST_URI'], '/') . '</td> </tr> </table> </div> <div id="info"> ' . $message . ' </div> <div id="explanation"> <p> You\'re seeing this error because you have <code>APP_DEBUG = True</code> in your index.php file. Change that to <code>False</code>, and Kotori.php will display a standard 404 page. </p> </div> </body> </html>'; } else { $tpl = file_get_contents(Config::getSoul()->APP_FULL_PATH . '/views/' . $tplPath . '.html'); } $tpl = str_replace('{$message}', $message, $tpl); $htmlParser = htmlParserFactory::construct(); $tpl = $htmlParser->compress($tpl); exit($tpl); }
/** * Map URL to controller and action * * @return void */ public function dispatch() { if (Config::getSoul()->URL_MODE == 'QUERY_STRING') { $this->_uri = explode('?', $this->_uri, 2); $_SERVER['QUERY_STRING'] = isset($this->_uri[1]) ? $this->_uri[1] : ''; $this->_uri = $this->_uri[0]; parse_str($_SERVER['QUERY_STRING'], $_GET); } define('URI', $this->_uri); switch ($this->_uri) { case 'favicon.ico': Response::getSoul()->setHeader('Content-Type', 'image/x-icon'); Response::getSoul()->setCacheHeader(); echo base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', Helper::logo())); exit; case 'kotori-php-system-route/highlight-github.css': Response::getSoul()->setHeader('Content-Type', 'text/css; charset=utf-8'); Response::getSoul()->setCacheHeader(); echo file_get_contents(Helper::getComposerVendorPath() . '/components/highlightjs/styles/github.css'); exit; case 'kotori-php-system-route/highlight.js': Response::getSoul()->setHeader('Content-Type', 'text/javascript; charset=utf-8'); Response::getSoul()->setCacheHeader(); echo file_get_contents(Helper::getComposerVendorPath() . '/components/highlightjs/highlight.pack.min.js'); exit; } $parsedRoute = $this->parseRoutes($this->_uri); if ($parsedRoute) { $this->_uri = $parsedRoute; } else { throw new \Exception('Request URI ' . $this->_uri . ' is not Matched by any route.'); } $this->_uris = $this->_uri != '' ? explode('/', trim($this->_uri, '/')) : array(); //Clean uris foreach ($this->_uris as $key => $value) { if ($value == '') { unset($this->_uris[$key]); } } $this->_uris = array_merge($this->_uris); $this->_controller = $this->getController(); $this->_action = $this->getAction(); //Define some variables define('CONTROLLER_NAME', $this->_controller); define('ACTION_NAME', $this->_action); define('PUBLIC_DIR', Request::getSoul()->getBaseUrl() . 'public'); //If is already initialized $prefix = Config::getSoul()->NAMESPACE_PREFIX; $controllerClassName = $prefix . 'controllers\\' . $this->_controller; if (isset($this->_controllers[$this->_controller])) { $class = $this->_controllers[$this->_controller]; } else { $class = new $controllerClassName(); $this->_controllers[$this->_controller] = $class; } if (!class_exists($controllerClassName)) { throw new \Exception('Request Controller ' . $this->_controller . ' is not Found.'); } if (!method_exists($class, $this->_action)) { throw new \Exception('Request Action ' . $this->_action . ' is not Found.'); } //Parse params from uri $this->_params = $this->getParams(); //Do some final cleaning of the params $_GET = array_merge($this->_params, $_GET); $_REQUEST = array_merge($_POST, $_GET, $_COOKIE); Response::getSoul()->setHeader('X-Powered-By', 'Kotori'); Response::getSoul()->setHeader('Cache-control', 'private'); //Call the requested method call_user_func_array(array($class, $this->_action), $this->_params); }