/** * Construct the Controller */ public function __construct() { if (Request::is_api_call() || Request::is_ajax()) { $this->_view = new JSONView(); } else { $this->_view = new HTMLView(); } }
/** * Test Database Connection * * @param array $params * @throws GenericException */ public function test_database($params) { try { if (Request::is_ajax()) { $body = json_decode(Request::get_request_body()); $database = new Database($body->type, $body->host, $body->name, $body->user, $body->pass, $body->char); } else { throw new GenericException('Invalid Request', 400); } } catch (DatabaseException $e) { $protocol = isset(Request::server()['SERVER_PROTOCOL']) ? Request::server()['SERVER_PROTOCOL'] : 'HTTP/1.0'; header($protocol . ' 404 Not Found'); } }
/** * Error view generation * * @param string|integer $a_code * @param string $a_message * @param Exception $a_exception * @return MVC\View */ public function custom($a_code, $a_message, Exception $a_exception = null) { $this->_view->set_param('code', $a_code); $this->_view->set_param('message', $a_message); if (Core\Request::is_api_call() || Core\Request::is_ajax()) { $this->_view->set_param('request', Core\Request::get()['request']); } else { $this->_view->set_title($a_message); $this->_view->set_view('error'); } if ($a_exception !== null && !is_array($a_exception)) { $this->_view->set_param('file', $a_exception->getFile()); $this->_view->set_param('line', $a_exception->getLine()); if (Application\Application::get_instance()->get_mode() === APINE_MODE_DEVELOPMENT) { $this->_view->set_param('trace', $a_exception->getTraceAsString()); } } if ($this->is_http_code($a_code)) { $this->_view->set_response_code($a_code); } else { $this->_view->set_response_code(500); } return $this->_view; }