/** * errorHandler * * Custom error handler function * * @param int $no * @param string $str * @param string $file * @param int $line * @param string $context */ public function errorHandler($no, $str, $file, $line, $context) { // Check if error is included in error reporting if (!(error_reporting() & $no)) { return; } // Get error type $type = $this->_getError($no); // Log error \nanophp\Libraries\Application::logger()->log($type, "{$str} on {$file}:{$line}"); }
/** * Route a custom, web or cli request * * @param string $request */ public function route($request = null) { // Parse request data $this->_parse($request); // Create Clas name space $class = PHP_SAPI !== 'cli' ? "\\app\\Controllers\\{$this->controller}Controller" : "\\app\\Commands\\{$this->controller}Command"; // Create action method $method = "{$this->action}Action"; // Create Logging info $logInfo = ['params' => $this->_params, 'queris' => $this->_query_strings, 'SAPI' => PHP_SAPI]; // Check if class and its method do exist and then call them using // params if (class_exists($class)) { $controller = new $class(); if (method_exists($controller, $method)) { call_user_func_array(array($controller, $method), $this->_params); \nanophp\Libraries\Application::logger()->info("{$this->controller}/{$this->action}", $logInfo); return; } } header("HTTP/1.0 404 Not Found"); \nanophp\Libraries\Application::logger()->error("{$this->controller}/{$this->action}", $logInfo); //TODO: Implement 404 template }