Example #1
0
 public static function route()
 {
     $action = Config::get('ctrl_path', 'ctrl') . '\\' . Request::getCtrl();
     $view = null;
     try {
         $class = Factory::getInstance($action);
         if (!$class instanceof IController) {
             throw new \Exception("ctrl error");
         } else {
             $class->_before();
             $method = Request::getMethod();
             if (!method_exists($class, $method)) {
                 throw new \Exception("method error");
             }
             $view = $class->{$method}();
             $class->_after();
             if (null === $view) {
                 return null;
             }
             return Response::display($view);
         }
     } catch (\Exception $e) {
         if (Request::isLongServer()) {
             return \call_user_func(Config::getField('project', 'exception_handler', 'ZPHP\\ZPHP::exceptionHandler'), $e);
         }
         throw $e;
     }
 }
Example #2
0
 public static function getViewMode()
 {
     if (Request::isLongServer()) {
         return ZConfig::getField('project', 'view_mode', 'Json');
     }
     if (\ZPHP\Common\Utils::isAjax()) {
         return 'Json';
     }
     return 'Php';
 }
Example #3
0
 public static function checkTime()
 {
     if (Request::isLongServer()) {
         if (self::$nextCheckTime < time()) {
             if (self::$lastModifyTime < \filectime(self::$configPath)) {
                 self::load(self::$configPath);
             }
         }
     }
     return;
 }
Example #4
0
File: Xml.php Project: heesey/zphp
 public function display()
 {
     if (Request::isHttp()) {
         Response::header("Content-Type", "text/xml; charset=utf-8");
     }
     $data = $this->xmlEncode();
     if (Request::isLongServer()) {
         return $data;
     }
     echo $data;
     return null;
 }
Example #5
0
 public function display()
 {
     if (Request::isHttp()) {
         Response::header('Content-Type', 'application/amf; charset=utf-8');
     }
     $data = \amf3_encode($this->model);
     if (Request::isLongServer()) {
         return $data;
     }
     echo $data;
     return null;
 }
Example #6
0
 public function display()
 {
     $pack = new MessagePacker();
     $pack->writeString(json_encode($this->model));
     if (Request::isHttp()) {
         Response::header("Content-Type", "application/zpack; charset=utf-8");
     }
     if (Request::isLongServer()) {
         return array($this->model, $pack->getData());
     }
     echo $pack->getData();
     return null;
 }
Example #7
0
File: Str.php Project: heesey/zphp
 public function display()
 {
     if (Request::isHttp()) {
         Response::header("Content-Type", "text/plain; charset=utf-8");
     }
     if (\is_string($this->model)) {
         $data = $this->model;
     } else {
         $data = json_encode($this->model);
     }
     if (Request::isLongServer()) {
         return $data;
     }
     echo $data;
     return null;
 }
Example #8
0
 public function display()
 {
     if (Request::isHttp()) {
         $params = Request::getParams();
         if (isset($params['jsoncallback'])) {
             Response::header("Content-Type", 'application/x-javascript; charset=utf-8');
         } else {
             Response::header("Content-Type", "application/json; charset=utf-8");
         }
     }
     $data = \json_encode($this->model);
     if (Request::isLongServer()) {
         return $data;
     }
     echo $data;
     return null;
 }
Example #9
0
 public function display()
 {
     $data = \json_encode($this->model, JSON_UNESCAPED_UNICODE);
     if (Request::isHttp()) {
         $params = Request::getParams();
         $key = Config::getField('project', 'jsonp', 'jsoncallback');
         if (isset($params[$key])) {
             Response::header("Content-Type", 'application/x-javascript; charset=utf-8');
             $data = $params[$key] . '(' . $data . ')';
         } else {
             Response::header("Content-Type", "application/json; charset=utf-8");
         }
     }
     if (Request::isLongServer()) {
         return $data;
     }
     echo $data;
     return null;
 }
Example #10
0
 public function display()
 {
     $jsonData = \json_encode($this->model);
     $data = gzencode($jsonData);
     $pack = new MessagePacker();
     $len = strlen($data);
     $pack->writeInt($len + 16);
     $pack->writeInt($this->model['cmd']);
     $pack->writeInt($this->model['rid']);
     $pack->writeString($data, $len);
     if (Request::isHttp()) {
         Response::header("Content-Type", "application/zrpack; charset=utf-8");
     }
     if (Request::isLongServer()) {
         return array($jsonData, $pack->getData());
     }
     echo $pack->getData();
     return null;
 }
Example #11
0
 public function display()
 {
     $tplPath = ZPHP\Core\Config::getField('project', 'tpl_path', ZPHP\ZPHP::getRootPath() . DS . 'template' . DS . 'default' . DS);
     $fileName = $tplPath . $this->tplFile;
     if (!\is_file($fileName)) {
         throw new \Exception("no file {$fileName}");
     }
     if (!empty($this->model)) {
         \extract($this->model);
     }
     if (ZPHP\Protocol\Request::isLongServer()) {
         \ob_start();
         include "{$fileName}";
         $content = ob_get_contents();
         \ob_end_clean();
         return $content;
     }
     include "{$fileName}";
     return null;
 }
Example #12
0
 public static function start($sessionType = '', $config = '')
 {
     if (Request::isLongServer()) {
         return Swoole::start($sessionType, $config);
     }
     if (false === self::$isStart) {
         if (empty($config)) {
             $config = ZConfig::get('session');
         }
         if (!empty($config['adapter'])) {
             $sessionType = $config['adapter'];
         }
         $lifetime = 0;
         if (!empty($config['cache_expire'])) {
             \session_cache_expire($config['cache_expire']);
             $lifetime = $config['cache_expire'] * 60;
         }
         $path = empty($config['path']) ? '/' : $config['path'];
         $domain = empty($config['domain']) ? '' : $config['domain'];
         $secure = empty($config['secure']) ? false : $config['secure'];
         $httponly = !isset($config['httponly']) ? true : $config['httponly'];
         \session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
         $sessionName = empty($config['session_name']) ? 'ZPHPSESSID' : $config['session_name'];
         \session_name($sessionName);
         if (!empty($_GET[$sessionName])) {
             \session_id($_GET[$sessionName]);
         } elseif (!empty($_SERVER[$sessionName])) {
             \session_id($_SERVER[$sessionName]);
         }
         if (!empty($sessionType)) {
             $handler = self::getInstance($sessionType, $config);
             \session_set_save_handler(array($handler, 'open'), array($handler, 'close'), array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'));
         }
         \session_start();
         self::$isStart = true;
     }
 }
Example #13
0
 private function connect()
 {
     if (Request::isLongServer()) {
         $persistent = 0;
     } else {
         $persistent = empty($this->config['pconnect']) ? 0 : 1;
     }
     return new \PDO($this->config['dsn'], $this->config['user'], $this->config['pass'], array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES '{$this->config['charset']}';", \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_PERSISTENT => $persistent));
 }