public function showAction(mfRequest $request) { mfResponse::getInstance()->setViewClass('mfMarkdownView'); $this->setTemplateDir(MF_CORE_DIR . DS . '..' . DS . 'doc' . DS . 'book'); $page = $request->getParameter('page'); // if(!file_exists($this->getTemplateDir() . DS . $page)) throw new mfException404("Page: $page not found"); $this->setTemplate($page); }
public function process_response() { if (!mfConfig::get('enable_toolbar', false)) { return; } $params = array('logs' => mfLogger::getLogs()); $params = array_merge($params, mfController::getMagicViewVars()); list($tpl, $view_class) = findTemplateFileName(MF_CORE_DIR . DS . 'default' . DS . 'toolbar'); $toolbar = new $view_class($tpl, $params); $response = mfResponse::getInstance(); $new_body = str_replace('</body>', $toolbar->getOutput() . '</body>', $response->getBody()); $response->setBody($new_body); }
/** * Output the added stylesheets */ function include_stylesheets() { // we may have new stylesheet if ($new = func_get_args()) { mfResponse::getInstance()->addStylesheet($new); } $files = mfResponse::getInstance()->getStylesheets(); $output = ''; foreach ($files as $file) { $output .= "<link type='text/css' rel='stylesheet' href='/css/{$file}.css' />\n"; // TODO rewrite it ,hard code here } echo $output; }
public static function dispatch() { // Initial middleware classes $middleware_classes = mfConfig::get('middlewares', array()); $middlewares = array(); foreach ($middleware_classes as $middleware_class) { require_once "middleware/{$middleware_class}.php"; $middlewares[] = new $middleware_class(); } // =========================================== // start process request $request = mfRequest::getInstance(); foreach ($middlewares as $middleware) { if (method_exists($middleware, 'process_request')) { $middleware->process_request($request); } } // end process request // =========================================== // Core Process $controller = $request->getController(); $action = $request->getAction(); $controller_class = ucfirst($controller) . 'Controller'; if (!class_exists($controller_class)) { throw new MfException("Can't find Controller: {$controller_class}"); } $controller = new $controller_class(); if (!$controller instanceof mfController) { throw new MfException("Controller:{$controller_class} must extend from mfController class"); } $controller->execute($action . 'Action', $request); // End Core Process // =========================================== // start process response $response = mfResponse::getInstance(); // response middleware process in the reverse direction foreach (array_reverse($middlewares) as $middleware) { if (method_exists($middleware, 'process_response')) { $middleware->process_response($response); } } // end process response }
protected function render() { // Magic view variables $magic_vars = self::getMagicViewVars(); // merge $this->_view_vars_ = array_merge($magic_vars, $this->_view_vars_); $this->_layout_vars_ = array_merge($magic_vars, $this->_layout_vars_); list($template, $view_class) = findTemplateFileName($this->getTemplateDir() . DS . $this->getTemplate()); $view = new $view_class($template, $this->_view_vars_); // render layout if ($this->_layout_) { // content here $this->_layout_vars_['mf_layout_content'] = $view->getOutput(); list($layout_file, $layout_class) = findTemplateFileName($this->getLayoutDir() . DS . $this->getLayout()); $layout = new $layout_class($layout_file, $this->_layout_vars_); mfResponse::getInstance()->setBody($layout->getOutput()); } else { // no layout mfResponse::getInstance()->setBody($view->getOutput()); } }
/** * get instance * * @return mfResponse */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
function has_slot($name) { return mfResponse::getInstance()->getSlot($name); }