/** * Contrutor da classe * @param string $url url acessada pelo usuário */ public function __construct($url) { define('CACHE_TIME', 60); $cache_config = Config::get('cache'); if ($cache_config['page']) { $cache = Cache::factory(); if ($cache->has(URL)) { $data = $cache->read(URL); exit($data); } } $registry = Registry::getInstance(); $this->args = $this->args($url); //I18n define('lang', $this->args['lang']); define('LANG', $this->args['lang']); $i18n = I18n::getInstance(); $i18n->setLang(LANG); $registry->set('I18n', $i18n); function __($string, $format = null) { return I18n::getInstance()->get($string, $format); } function _e($string, $format = null) { echo I18n::getInstance()->get($string, $format); } define('controller', Inflector::camelize($this->args['controller']) . 'Controller'); define('action', str_replace('-', '_', $this->args['action'])); define('CONTROLLER', Inflector::camelize($this->args['controller']) . 'Controller'); define('ACTION', str_replace('-', '_', $this->args['action'])); try { header('Content-type: text/html; charset=' . Config::get('charset')); Import::core('Controller', 'Template', 'Annotation'); Import::controller(CONTROLLER); $this->controller(); $this->auth(); $tpl = new Template(); $registry->set('Template', $tpl); $tpl->render($this->args); if ($cache_config['page']) { $cache = Cache::factory(); $data = ob_get_clean(); $cache->write(URL, $data, $cache_config['time']); } Debug::show(); } catch (PageNotFoundException $e) { header('HTTP/1.1 404 Not Found'); $this->loadError($e); exit; } catch (Exception $e) { header('HTTP/1.1 500 Internal Server Error'); $this->loadError($e); } }
public function handle_request($params) { if (array_key_exists("format", $params) === false) { $params["format"] = "html"; } $this->params = $params; $controller_name = Inflector::camelize($params["controller"], "first"); Logger::process_controller($controller_name, $params["action"], env("REQUEST_METHOD"), $params); if (Import::controller($params["controller"])) { Import::helper($params["controller"]); $helper_name = "{$controller_name}Helper"; $this->controller = new $controller_name($this->request_uri, $params); if (class_exists($helper_name)) { $this->controller->helper = new $helper_name(); } $action = $params["action"]; } else { $this->controller = new self($this->request_uri, $params); $action = "not_found"; $this->controller->{$action}(); } $this->controller->format = $this->params["format"]; $this->controller->handle_action($action); }
* @param <type> $preg * @param <type> $module * @param <type> $func * @return <type> */ function rewrite($preg, $module, $func) { if (!$this->rewrite) { preg_match_all($preg, $_SERVER['REQUEST_URI'], $rt); if (isset($rt['0']['0']) && $rt['0']['0'] != '') { if (isset($rt['1'])) { $args = $rt['1']; } $this->module = $module; $this->function = $func; if (!empty($args)) { $this->parms = array_merge($args, $this->parms); } $this->rewrite = true; } } return $this->rewrite; } } /** * Running */ $app = Import::controller(); $app->App = Import::model(); $re = Import::route(); call_user_func_array(array($app, 'action'), $re->load());