Beispiel #1
0
 public function run($data, $fd = null)
 {
     $server = Protocol\Factory::getInstance(Core\Config::getField('socket', 'protocol', 'Http'));
     $server->setFd($fd);
     $server->parse($data);
     return Core\Route::route($server);
 }
Beispiel #2
0
 /**
  *  请求发起
  */
 public function onRequest($request, $response)
 {
     Utils::$response = $response;
     $this->protocol->parse($_REQUEST);
     $result = Core\Route::route($this->protocol);
     return $response->end($result);
 }
Beispiel #3
0
 public function run()
 {
     $server = Protocol\Factory::getInstance('Cli');
     Protocol\Request::setServer($server);
     Protocol\Request::parse($_SERVER['argv']);
     return Core\Route::route();
 }
Beispiel #4
0
 public function onRequest($request, $response)
 {
     $filename = ZPHP::getRootPath() . DS . 'webroot' . $request->server['path_info'];
     if (is_file($filename)) {
         //解析静态文件
         $response->header("Content-Type", $this->getMime($filename) . '; charset=utf-8');
         $response->end(file_get_contents($filename));
         return;
     }
     $param = [];
     if (!empty($request->get)) {
         $param = $request->get;
     }
     if (!empty($request->post)) {
         $param += $request->post;
     }
     $_SERVER['HTTP_USER_AGENT'] = $request->header['user-agent'];
     Request::parse($param);
     Request::setViewMode('Php');
     Request::setHttpServer(1);
     Response::setResponse($response);
     try {
         $result = ZRoute::route();
     } catch (\Exception $e) {
         $model = Formater::exception($e);
         $model['_view_mode'] = 'Json';
         $result = Response::display($model);
     }
     $response->end($result);
     Request::setViewMode(ZConfig::getField('project', 'view_mode', 'Json'));
     Request::setHttpServer(0);
 }
Beispiel #5
0
 public function api($params)
 {
     if (!$this->protocol) {
         $this->protocol = Protocol\Factory::getInstance('Rpc');
     }
     $this->protocol->parse($params);
     return Core\Route::route($this->protocol);
 }
Beispiel #6
0
 public function run()
 {
     if (!$this->protocol) {
         $this->protocol = Protocol\Factory::getInstance('Cli');
     }
     $this->protocol->parse($_SERVER['argv']);
     return Core\Route::route($this->protocol);
 }
Beispiel #7
0
 public function run()
 {
     if (!$this->protocol) {
         $this->protocol = Protocol\Factory::getInstance('Http');
     }
     $this->protocol->parse($_REQUEST);
     return Core\Route::route($this->protocol);
 }
Beispiel #8
0
 private function route($server)
 {
     try {
         Core\Route::route($server);
     } catch (\Exception $e) {
         $server->display($e->getMessage());
     }
     return $server;
 }
Beispiel #9
0
 public function run($data)
 {
     $server = Protocol\Factory::getInstance('Http');
     $server->parse($data);
     \ob_start();
     Core\Route::route($server);
     $result = \ob_get_contents();
     \ob_end_clean();
     return $result;
 }
Beispiel #10
0
 public function onReceive()
 {
     list($serv, $fd, $fromId, $data) = func_get_args();
     if (empty($data)) {
         return;
     }
     Request::parse($data);
     $result = ZRoute::route();
     $serv->send($fd, $result);
 }
Beispiel #11
0
 public function onTask($server, $taskId, $fromId, $data)
 {
     Request::parse($data);
     Request::addParams('taskId', $taskId . '_' . $fromId);
     try {
         ZRoute::route();
     } catch (\Exception $e) {
         $model = Formater::exception($e);
         ZLog::info('exception', $model);
     }
 }
Beispiel #12
0
 public function run($data, $fd)
 {
     $server = Protocol\Factory::getInstance('ZRpack');
     $server->setFd($fd);
     $result = array();
     if (false === $server->parse($data)) {
         return $result;
     }
     $result[] = Core\Route::route($server);
     while ($server->parse("")) {
         $result[] = Core\Route::route($server);
     }
     return $result;
 }
Beispiel #13
0
 public function onRequest($request, $response)
 {
     $param = [];
     if (!empty($request->get)) {
         $param = $request->get;
     }
     if (!empty($request->post)) {
         $param += $request->post;
     }
     Request::parse($param);
     try {
         $result = ZRoute::route();
     } catch (\Exception $e) {
         $model = Formater::exception($e);
         $model['_view_mode'] = 'Json';
         $result = Response::display($model);
     }
     $response->end($result);
 }
Beispiel #14
0
 public function onMessage($server, $frame)
 {
     if (empty($frame->finish)) {
         //数据未完
         if (empty($this->buff[$frame->fd])) {
             $this->buff[$frame->fd] = $frame->data;
         } else {
             $this->buff[$frame->fd] .= $frame->data;
         }
     } else {
         if (!empty($this->buff[$frame->fd])) {
             $frame->data = $this->buff[$frame->fd] . $frame->data;
             unset($this->buff[$frame->fd]);
         }
     }
     Request::parse($frame->data);
     $result = ZRoute::route();
     $server->push($frame->fd, $result);
 }
Beispiel #15
0
 public function onRequest($request, $reponse)
 {
     $content = "";
     do {
         $path_info = explode("/", $request->server['path_info']);
         $ctrl = $path_info[1];
         $method = $path_info[2];
         if (isset($request->post)) {
             Protocol\Request::parse($request->post);
         } else {
             Protocol\Request::parse($request->rawContent());
         }
         Protocol\Request::setCtrl($ctrl);
         Protocol\Request::setMethod($method);
         Protocol\Request::setViewMode('Json');
         Protocol\Request::setSocket($this->serv);
         //\ob_start();
         $content = Core\Route::route();
         //$content = \ob_get_contents();
         //\ob_end_clean();
     } while (0);
     $reponse->end($content);
 }
Beispiel #16
0
 public function onMessage($serv, $frame)
 {
     if (empty($frame->finish)) {
         if (empty($this->buffer[$frame->fd])) {
             $this->buffer[$frame->fd] = $frame->data;
         } else {
             $this->buffer[$frame->fd] .= $frame->data;
         }
         return;
     }
     if (!empty($this->buffer[$frame->fd])) {
         $frame->data = $this->buffer[$frame->fd] . $frame->data;
         unset($this->buffer[$frame->fd]);
     }
     if (empty($frame->data)) {
         return;
     }
     $this->protocol->parse($frame->data);
     $result = Core\Route::route($this->protocol);
     if (is_null($result)) {
         return;
     }
     return $frame->push($result);
 }
Beispiel #17
0
 public function onClose()
 {
     Request::setFd(func_get_arg(1));
     Request::parse(['a' => 'chat', 'm' => 'offline']);
     ZRoute::route();
 }
Beispiel #18
0
 public function api($params)
 {
     Protocol\Request::setServer(Protocol\Factory::getInstance('Rpc'));
     Protocol\Request::parse($params);
     return Core\Route::route();
 }
Beispiel #19
0
 public function run()
 {
     $server = Protocol\Factory::getInstance('Http');
     $server->parse($_REQUEST);
     Core\Route::route($server);
 }
Beispiel #20
0
 public function run()
 {
     $server = Protocol\Factory::getInstance('Protocol\\WebSocket');
     $server->parse($_REQUEST);
     return Core\Route::route($server);
 }
Beispiel #21
0
 private function _route($data)
 {
     try {
         $server = Protocol\Factory::getInstance(ZConfig::getField('socket', 'protocol', 'Rpc'));
         $server->parse($data);
         $result = Core\Route::route($server);
         return $result;
     } catch (\Exception $e) {
         $result = Formater::exception($e);
         ZPHP\Common\Log::info('zchat', [var_export($result, true)]);
         return null;
     }
 }
Beispiel #22
0
 public function run()
 {
     Protocol\Request::setServer(Protocol\Factory::getInstance('Http'));
     Protocol\Request::parse($_REQUEST);
     return Core\Route::route();
 }
Beispiel #23
0
 public function run()
 {
     $server = Protocol\Factory::getInstance('Cli');
     $server->parse($_SERVER['argv']);
     Core\Route::route($server);
 }
Beispiel #24
0
 public function api($params)
 {
     $server = Protocol\Factory::getInstance('Rpc');
     $server->parse($params);
     return Core\Route::route($server);
 }