public function __destruct() { if (defined('IS_PROFILING')) { \App::profiler()->log("Destroying view observer"); if ($this->observer) { unset($this->observer); } } }
public function invoke($action, $args) { if (defined('IS_PROFILING')) { \App::profiler()->log('Invoking controller'); } // Begin the document, and assign it as the response document $this->document = Document::begin(Document::DT_HTML5, 'en-us', 'UTF-8'); $this->response->setDocument($this->document); $this->setup(); $handler = [$this, $action . 'Action']; if (is_callable($handler)) { call_user_func_array($handler, $args); $this->response->output(); } else { $this->show_404(); } //$this->indexAction($doc); // Output the document }
private function load($file) { if (defined('IS_PROFILING')) { \App::profiler()->log("Loading and parsing view"); } ob_start(); include $file; //ob_start(array($this,'__ob_callback')); //ob_end_flush(); $fout = ob_get_contents(); ob_end_clean(); $fout = $this->parseViewTags($fout); return $fout; }
public function route() { $uri = $this->request->getUri(); foreach ($this->passthru as $rule => $target) { if (fnmatch($rule, $uri)) { if ($target == null) { $file = APP_PUBLIC . _DS_ . $uri; } else { $file = APP_ROOT . _DS_ . $target . $uri; } if (file_exists($file)) { $this->response->setCacheControl('public,max-age=3600'); $this->response->sendFile($file); } else { $this->response->send404($file); } \App::server()->log('%s: %s', (string) $this->request, (string) $this->response); return; } } foreach ($this->routes as $rule => $route) { $re = str_replace('/', '\\/', $rule); $re = str_replace(':str', '[a-zA-Z\\.,\\-]*', $re); $match = []; if (preg_match("/^{$re}/", $uri, $match)) { for ($n = 1; $n < count($match); $n++) { $route = str_replace('$' . $n, $match[$n], $route); } if (strpos($route, ':') !== false) { list($tctl, $tparms) = explode(':', $route); } else { list($tctl, $tparms) = [$route, '']; } $tcclass = explode('/', $tctl); $tcmethod = array_pop($tcclass); $tparms = (array) explode(',', $tparms); $tcargs = []; foreach ($tparms as $parm) { if ($parm && $parm[0] == '$') { $tcargs[] = $match[intval(substr($parm, 1))]; } } require_once 'controllers' . _DS_ . strtolower(join(_DS_, $tcclass)) . '.php'; if (count($tcclass) == 1) { // Append app namespace $tcclass = ucwords($tcclass[0]) . 'Controller'; } else { $tcclass = "\\" . join("\\", $tcclass) . 'Controller'; } $tcclass = str_replace("\\\\", "\\", APP_NS . "\\Controllers\\" . $tcclass); if (!$tcmethod) { $tcmethod = 'index'; } \App::server()->log('%s => %s:%s [%s] (%s)', (string) $this->request, ucwords($tcclass), $tcmethod, join(',', $tcargs), substr($this->request->getHeader('User-Agent'), 0, 40)); if (defined('IS_PROFILING')) { \App::profiler()->log('Calling controller'); } $ctl = new $tcclass($this->request, $this->response); $ctl->invoke($tcmethod, $tcargs); return true; } } }