/** * 构造 * * @param array $params => array ( * host => (string) 主机,默认值为空 * port => (int) 端口,默认值为空 * * prefix => (string) 缓存名前缀,默认值为空 * ) * @return Cache_Abstract */ public function __construct($params) { $this->_exception = Exceptions::getInstance(); if (!is_array($params)) { if ($this->_exception->throwExceptions()) { throw new Exception('Adapter params must be in an array.'); } else { $this->_exception->sendHttpStatus(500); } } $this->_params = $params; }
/** * 调派 */ private function dispatch() { $this->controller = $this->_router->_controller; $this->action = $this->_router->_action; $controllerName = ucfirst($this->controller) . 'Controller'; $controllerFile = APP_PATH . DIRECTORY_SEPARATOR . 'Controllers' . DIRECTORY_SEPARATOR . $controllerName . '.php'; if (file_exists($controllerFile)) { include_once $controllerFile; } else { if ($this->_exception->throwExceptions()) { throw new Exception('Controller "' . $controllerFile . '" not found.'); } else { $this->_exception->sendHttpStatus(404); } } if (class_exists($controllerName)) { $controller = new $controllerName(); } else { if ($this->_exception->throwExceptions()) { throw new Exception($controllerName . ' does not exist.'); } else { $this->_exception->sendHttpStatus(404); } } $action = $this->_router->_action . 'Action'; if (method_exists($controller, $action)) { $controller->{$action}(); } else { if ($this->_exception->throwExceptions()) { throw new Exception('Action "' . $this->_router->_action . '" does not exist.'); } else { $this->_exception->sendHttpStatus(404); } } }
/** * 渲染 * */ public function display() { $viewTpl = APP_PATH . DIRECTORY_SEPARATOR . 'Views' . DIRECTORY_SEPARATOR . strtolower($this->_controller) . DIRECTORY_SEPARATOR . $this->_action . '.php'; if (file_exists($viewTpl)) { $this->_render = $viewTpl; } else { if ($this->_exception->throwExceptions()) { throw new Exception('View "' . $this->_action . '" does not exist.'); } else { $this->_exception->sendHttpStatus(404); } } include $this->_render; }
/** * 构造 * * @param array $params => array ( * host => (string) 主机,默认值为localhost * dbname => (string) 数据库名 * username => (string) 用户名 * passwd => (string) 密码 * * port => (string) 端口 * charset => (string) 字符集编码,默认值为utf8 * persistent => (boolean) 是否启用持久连接,默认值为false * ) * @return Db_Abstract */ public function __construct($params) { $this->_exception = Exceptions::getInstance(); if (!is_array($params)) { if ($this->_exception->throwExceptions()) { throw new Exception('Adapter params must be in an array.'); } else { $this->_exception->sendHttpStatus(500); } } if (!isset($params['charset'])) { $params['charset'] = 'utf8'; } if (!isset($params['persistent'])) { $params['persistent'] = false; } $this->_params = $params; }