public function __construct() { $this->data = new Helper\Set(); $this->vitex = Vitex::getInstance(); $this->tplext = $this->vitex->getConfig('templates.ext'); $this->setTplPath($this->vitex->getConfig('templates.path')); }
public function __construct($table = '') { $this->vitex = Vitex::getInstance(); try { $this->DB = $this->vitex->pdo; $this->pdo = $this->DB->pdo; } catch (Exception $e) { throw new \Error('使用ORM之前您必须要调用一个数据库连接的类返回一个PDO的变量,或者直接加载pdo中间件'); } if ($table) { $this->from($table); } $class = explode('\\', get_class($this)); $this->table = strtolower(end($class)); }
/** * 执行中间件和上传操作的方法 */ public function call() { if ($this->vitex) { $vitex = $this->vitex; } else { $vitex = Vitex::getInstance(); } $this->moveFile(); $vitex->req->upload = $this->return; $vitex->req->uploadError = $this->getError(); $this->runNext(); return $this->return; }
/** * 直接输出模板信息 * @param string $tpl 模板地址 * @param array $data 传递给模板的数据 * @param int $status 状态 */ public function render($tpl, array $data = [], $status = null) { $vitex = Vitex::getInstance(); $vitex->render($tpl, $data, $status); }
/** * 一个兼容的pathinfo获取方法 * 如果包含分组,这里要重写pathinfo的信息 * @return array|null|string */ public function getPathinfo() { //pathinfo已经被重写过 if ($this->_pathinfo !== null) { return $this->_pathinfo; } $pathinfo = $this->get('PATH_INFO'); if (!$pathinfo) { //兼容模式 $vitex = \Vitex\Vitex::getInstance(); if ($vitex->getConfig('router.compatible')) { $pathinfo = isset($_GET['u']) ? $_GET['u'] : ''; } } return $pathinfo; }
/** * 直接输出模板信息 * @param string $tpl 模板地址 * @param array $data 传递给模板的数据 * @param int $status 状态码,默认会输出200 */ public function render($tpl, array $data = [], $status = null) { $this->vitex->render($tpl, $data, $status); }
/** * 执行下一个匹配的URL规则 * @return self */ public function next() { if (!$this->_router) { $this->_router = $this->router->getRouter(); } $vitex = Vitex::getInstance(); $call = $this->_router->current(); if (is_callable($call)) { call_user_func($call, $vitex->req, $vitex->res, function () { $this->nextRouter(); }); } else { call_user_func($this->_notfound, $vitex->req, $vitex->res, function () { $this->nextRouter(); }); } return $this; }
/** * 根据路由信息实例化相应的控制器类来返回函数方法对象 * @param string $str 字符串 * @param string $httpmethod http请求的方法 * @return callable 可执行的方法 */ public function getCallable($str, $httpmethod) { $strs = explode('@', $str); $class = array_shift($strs); $method = strtolower($strs ? array_pop($strs) : $httpmethod); //完全限定命名空间 if ($class[0] != '\\') { //当前应用 $vitex = Vitex::getInstance(); $app = $vitex->appName; $class = '\\' . ucfirst($app) . '\\Controller\\' . $class; } $obj = new $class(); if (!$obj || !method_exists($obj, $method)) { Vitex::getInstance()->log->error('Class:' . $class . '->' . $method . ' Not Found!!'); return false; } return function () use($obj, $method) { return $obj->{$method}(); }; }