Example #1
0
 /**
  * 启动程序,查找相应的文件controller,action
  *
  * @return boolean
  */
 public function start()
 {
     $controller = $this->_route->getController();
     $action = $this->_route->getAction();
     $params = $this->_route->getParams();
     $controller = empty($controller) ? Config::get('indexController') : $controller;
     $className = "App\\Controller\\" . ucfirst($controller);
     if (!class_exists($className)) {
         return Render::getInstance()->setHeaders(['HTTP/1.1 404 Not Found'])->output("404 Not Found [CONTROLLER-NO-EXISTS:{$controller}]");
     }
     $ctrl = new $className();
     $action = empty($action) ? $ctrl->getDefaultAction() : $action;
     $method = $action . "Action";
     if (empty($action) || !method_exists($className, $method)) {
         return Render::getInstance()->setHeaders(['HTTP/1.1 404 Not Found'])->output("404 Not Found [ACTION-NO-EXISTS:{$controller}->{$action}]");
     }
     $data = call_user_func_array(array($ctrl, $method), $params);
     if (php_sapi_name() == 'cli') {
         return Render::getInstance()->output($data, false);
     } elseif (empty($ctrl->getView())) {
         return Render::getInstance()->setHeaders($ctrl->getHeaders())->output($data, true);
     } elseif (isset($_SERVER['Content-Type']) && $_SERVER['Content-Type'] == 'application/json') {
         return Render::getInstance()->setHeaders($ctrl->getHeaders())->output($data, true);
     }
     return Render::getInstance()->setHeaders($ctrl->getHeaders())->view($data, $ctrl->getViewFile(), $ctrl->getLayoutFile());
 }
Example #2
0
 /**
  * url重定向
  *
  * @return boolean 
  */
 protected function urlRewrite($routeArr)
 {
     $indexKey = array_search('index.php', $routeArr);
     $newRoute = array_slice($routeArr, $indexKey + 1);
     $url = '/' . implode('/', $newRoute);
     $_url = Config::route($url);
     if (empty($_url)) {
         return $newRoute;
     }
     return explode('/', trim($_url, '/'));
 }
Example #3
0
 /**
  * 初始化
  *
  * @return void
  */
 protected function init()
 {
     $config = Config::database($this->dbType, $this->dbSelect);
     switch ($this->dbType) {
         case 'mongodb':
             $dbClass = '\\PhpDb\\Mongodb\\PhpMongo';
             break;
         default:
             $dbClass = '\\PhpDb\\Pdo\\PhpPdo';
     }
     $this->db = $dbClass::getInstance()->connect($config, $this->dbType);
 }
Example #4
0
 public function submit()
 {
     $name = $this->request->post('name', 'string');
     $pass = $this->request->post('password', 'string');
     $code = $this->request->post('code', 'string');
     if (Config::auth($name) === null) {
         return ['status' => 1, 'msg' => '用户不存在'];
     }
     if ($pass != Config::auth($name)) {
         return ['status' => 1, 'msg' => '密码错误'];
     }
     if ($this->request->session('phrase', 'string') != $code) {
         return ['status' => 1, 'msg' => '验证码错误'];
     }
     $_SESSION['name'] = $name;
     return ['status' => 0];
 }
Example #5
0
 /**
  * 获取config文件值
  *
  * @param string $key  key
  * @param string $item item 
  *
  * @return string|int|array|null
  */
 public function getConfig($key = null, $item = null)
 {
     return Config::get($key, $item);
 }
Example #6
0
 public function testGetApp()
 {
     $this->assertNull(Config::getApp('debug', 'iuyfttds'));
 }
Example #7
0
 /**
  * 启动程序,查找相应的文件controller,action
  *
  * @return boolean
  */
 public function start()
 {
     $controller = $this->_route->getController();
     $action = $this->_route->getAction();
     $params = $this->_route->getParams();
     $controller = empty($controller) ? Config::get('indexController') : $controller;
     $className = "App\\Controllers\\" . ucfirst($controller);
     if (!class_exists($className)) {
         throw new \Exception("CONTROLLER-NO-EXISTS:{$controller}");
         return false;
     }
     $ctrl = new $className();
     $action = empty($action) ? $ctrl->getDefaultAction() : $action;
     if (!empty($action) && !method_exists($className, $action)) {
         throw new \Exception("ACTION-NO-EXISTS:{$controller}->{$action}");
         return false;
     }
     $data = call_user_func_array(array($ctrl, $action), $params);
     if (php_sapi_name() == 'cli') {
         Render::getInstance()->output($data, false);
     } elseif (empty($ctrl->getView())) {
         Render::getInstance()->setHeaders($ctrl->getHeaders())->output($data, true);
     } elseif (isset($_SERVER['Content-Type']) && $_SERVER['Content-Type'] == 'application/json') {
         Render::getInstance()->setHeaders($ctrl->getHeaders())->output($data, true);
     }
     Render::getInstance()->setHeaders($ctrl->getHeaders())->view($data, $ctrl->getViewFile(), $ctrl->getLayoutFile());
     return true;
 }