예제 #1
0
파일: Http.php 프로젝트: heesey/zphp
 /**
  * 直接 parse $_REQUEST
  * @param $_data
  * @return bool
  */
 public function parse($data)
 {
     $ctrlName = Config::getField('project', 'default_ctrl_name', 'main\\main');
     $methodName = Config::getField('project', 'default_method_name', 'main');
     $apn = Config::getField('project', 'ctrl_name', 'a');
     $mpn = Config::getField('project', 'method_name', 'm');
     if (isset($data[$apn])) {
         $ctrlName = \str_replace('/', '\\', $data[$apn]);
     }
     if (isset($data[$mpn])) {
         $methodName = $data[$mpn];
     }
     if (!empty($_SERVER['PATH_INFO'])) {
         //swoole_http模式 需要在onRequest里,设置一下 $_SERVER['PATH_INFO'] = $request->server['path_info']
         $routeMap = ZRoute::match(Config::get('route', false), $_SERVER['PATH_INFO']);
         if (is_array($routeMap)) {
             $ctrlName = \str_replace('/', '\\', $routeMap[0]);
             $methodName = $routeMap[1];
             if (!empty($routeMap[2]) && is_array($routeMap[2])) {
                 //参数优先
                 $data = $data + $routeMap[2];
             }
         }
     }
     Request::init($ctrlName, $methodName, $data, Config::getField('project', 'view_mode', 'Php'));
     return true;
 }
예제 #2
0
파일: Zpack.php 프로젝트: heesey/zphp
 /**
  * client包格式: writeString(json_encode(array("a"='main/main',"m"=>'main', 'k1'=>'v1')));
  * server包格式:包总长+数据(json_encode)
  * @param $_data
  * @return bool
  */
 public function parse($_data)
 {
     $ctrlName = Config::getField('project', 'default_ctrl_name', 'main\\main');
     $methodName = Config::getField('project', 'default_method_name', 'main');
     $fd = Request::getFd();
     if (!empty($this->_buffer[$fd])) {
         $_data = $this->_buffer . $_data;
     }
     $packData = new MessagePacker($_data);
     $packLen = $packData->readInt();
     $dataLen = \strlen($_data);
     if ($packLen > $dataLen) {
         $this->_buffer[$fd] = $_data;
         return false;
     } elseif ($packLen < $dataLen) {
         $this->_buffer[$fd] = \substr($_data, $packLen, $dataLen - $packLen);
     } else {
         if (!empty($this->_buffer[$fd])) {
             unset($this->_buffer[$fd]);
         }
     }
     $packData->resetOffset();
     $params = $packData->readString();
     $data = \json_decode($params, true);
     $apn = Config::getField('project', 'ctrl_name', 'a');
     $mpn = Config::getField('project', 'method_name', 'm');
     if (isset($params[$apn])) {
         $ctrlName = \str_replace('/', '\\', $params[$apn]);
     }
     if (isset($params[$mpn])) {
         $methodName = $params[$mpn];
     }
     Request::init($ctrlName, $methodName, $data, Config::getField('project', 'view_mode', 'Zpack'));
     return true;
 }
예제 #3
0
파일: Rpc.php 프로젝트: heesey/zphp
 /**
  * 直接 parse $_REQUEST
  * @param $data
  * @return bool
  */
 public function parse($data)
 {
     $ctrlName = Config::getField('project', 'default_ctrl_name', 'main\\main');
     $methodName = Config::getField('project', 'default_method_name', 'main');
     $apn = Config::getField('project', 'ctrl_name', 'a');
     $mpn = Config::getField('project', 'method_name', 'm');
     if (isset($data[$apn])) {
         $ctrlName = \str_replace('/', '\\', $data[$apn]);
     }
     if (isset($data[$mpn])) {
         $methodName = $data[$mpn];
     }
     Request::init($ctrlName, $methodName, $data, Config::getField('project', 'view_mode', 'Rpc'));
     return true;
 }
예제 #4
0
파일: ZRpack.php 프로젝트: tempbottle/zphp
 /**
  * 包格式: 包总长+命令id+请求id+数据
  * 
  * @param $_data
  * @return bool
  */
 public function parse($_data)
 {
     $ctrlName = Config::getField('project', 'default_ctrl_name', 'main\\main');
     $methodName = Config::getField('project', 'default_method_name', 'main');
     if (empty($this->_cache)) {
         $this->_cache = ZCache::getInstance('Php');
     }
     $fd = Request::getFd();
     $cacheData = $this->_cache->get($fd);
     if (!empty($cacheData)) {
         $_data = $cacheData . $_data;
         $this->_cache->delete($fd);
     }
     if (empty($_data)) {
         return false;
     }
     $packData = new MessagePacker($_data);
     $packLen = $packData->readInt();
     $dataLen = \strlen($_data);
     if ($packLen > $dataLen) {
         $this->_cache->set($fd, $_data);
         return false;
     } elseif ($packLen < $dataLen) {
         $this->_cache->set($fd, \substr($_data, $packLen, $dataLen - $packLen));
     }
     $packData->resetOffset(4);
     $data = [];
     $data['_cmd'] = $packData->readInt();
     $pathinfo = Config::getField('cmdlist', $data['_cmd']);
     $data['_rid'] = $packData->readInt();
     $params = $packData->readString();
     $unpackData = \json_decode(gzdecode($params), true);
     if (!empty($unpackData) && \is_array($unpackData)) {
         $data += $unpackData;
     }
     $routeMap = ZRoute::match(Config::get('route', false), $pathinfo);
     if (is_array($routeMap)) {
         $ctrlName = $routeMap[0];
         $methodName = $routeMap[1];
         if (!empty($routeMap[2]) && is_array($routeMap[2])) {
             //参数优先
             $data = $data + $routeMap[2];
         }
     }
     Request::init($ctrlName, $methodName, $data);
     return true;
 }
예제 #5
0
파일: Json.php 프로젝트: heesey/zphp
 public function parse($_data)
 {
     $ctrlName = Config::getField('project', 'default_ctrl_name', 'main\\main');
     $methodName = Config::getField('project', 'default_method_name', 'main');
     $data = [];
     if (!empty($_data)) {
         if (is_array($_data)) {
             $data = $_data;
         } else {
             $data = \json_decode($_data, true);
         }
     }
     $apn = Config::getField('project', 'ctrl_name', 'a');
     $mpn = Config::getField('project', 'method_name', 'm');
     if (isset($data[$apn])) {
         $ctrlName = \str_replace('/', '\\', $data[$apn]);
     }
     if (isset($data[$mpn])) {
         $methodName = $data[$mpn];
     }
     Request::init($ctrlName, $methodName, $data, Config::getField('project', 'view_mode', 'Json'));
     return true;
 }