public function execute() { global $events, $_SERVER; $this->_execute_services(); $method = router()->getMethodName(); $type = strtolower($_SERVER['REQUEST_METHOD']); if (method_exists(self::$controller, $type . $method)) { $method = $type . $method; } else { if (method_exists(self::$controller, 'any' . $method)) { $method = 'any' . $method; } else { show_error_404(); } } $this->_prepare(); try { if (method_exists(self::$controller, '_before')) { self::$controller->_before(); } $params = input()->get(); if (!empty($params)) { $content = call_user_func_array([self::$controller, $method], $params); } else { $content = call_user_func([self::$controller, $method]); } if (method_exists(self::$controller, '_after')) { self::$controller->_after(); } if (is_ajax()) { theme()->disable(); } theme()->display($content); } catch (AppException $e) { wasp_error($e->getMessage()); } \Wasp\Log::mySelf()->write(); }
public function __construct() { global $_REQUEST_URI; $superfluous = ['.html', '.htm', '.php5', '.php', '.php3', '.shtml', '.phtml', '.dhtml', '.xhtml', '.inc', '.cgi', '.pl', '.xml', '.js']; $this->uri = preg_replace("#/+#s", '/', $_REQUEST_URI); $this->uri = preg_replace(["#/\$#s", "#^/+#"], '', $this->uri); $this->uri = $this->request = str_replace($superfluous, '', $this->uri); $this->_load_routes(); if (array_count(self::$regexps) > 0) { foreach (self::$regexps as $key => $val) { if (preg_match('#' . $val['regexp'] . '#is', $this->uri)) { $this->uri = preg_replace('#' . $val['regexp'] . '#is', $val['replace'], $this->uri); break; } } } if (preg_match("%[^a-z0-9\\/\\-\\.]%isu", $this->uri)) { wasp_error("Abnormal request: {$this->uri}", 500); } class_alias('\\Wasp\\Router', '\\Router'); if (empty($this->uri)) { $this->controller = 'Index'; $this->method = 'Default'; $this->action = snake_case($this->controller) . '/' . snake_case($this->method); return; } $do = explode('/', $this->uri); $controller = isset($do[0]) ? $do[0] : null; $method = isset($do[1]) ? $do[1] : null; if (empty($controller) || !is_action_name($controller)) { $this->controller = 'Index'; $this->method = 'Default'; } else { $this->controller = studly_case($controller); if (empty($method) || !is_action_name($method)) { $this->method = 'Default'; } else { $this->method = studly_case($method); } } $this->action = snake_case($this->controller, '-') . '/' . snake_case($this->method, '-'); if ($this->controller == 'Coreinfo') { if ($this->method == 'Json') { $_ = new \stdClass(); $_->name = CORE_NAME; $_->description = FRAMEWORK; $_->version = CORE_VERSION; $_->status = CORE_VERSION_NAME; $_->author = 'Tishchenko Alexander'; if (!headers_sent()) { header('Cache-Control: no-cache, must-revalidate'); header('Expires: ' . date('r', time() - 86400)); header(CONTENT_TYPE_JSON); } exit(json_encode($_)); } else { if (!headers_sent()) { header(CONTENT_TYPE_XML); } exit("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<coreinfo>\n\t<name><![CDATA[" . CORE_NAME . "]]></name>\n\t<description><![CDATA[" . FRAMEWORK . "]]></description>\n\t" . "<version><![CDATA[" . CORE_VERSION . "]]></version>\n" . "\t<status><![CDATA[" . CORE_VERSION_NAME . "]]></status>\n" . "\t<author><![CDATA[Tishchenko Alexander]]></author>\n" . "</coreinfo>"); } } else { if ($this->controller == 'Phpinfo' && DEVELOP_MODE) { phpinfo(); exit; } else { if (!is_controller_exists($this->controller)) { show_error_404(); } } } array_shift($do); array_shift($do); $this->_set_get_params($do); }