diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..419a2e9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.idea +.DS_Store + +vendor +demo_composer/vendor +demo_composer/composer.lock \ No newline at end of file diff --git a/lib/Protocol/WebSocket.php b/lib/Protocol/WebSocket.php new file mode 100644 index 0000000..0a17c7e --- /dev/null +++ b/lib/Protocol/WebSocket.php @@ -0,0 +1,124 @@ +_ctrl = Config::getField('project', 'default_ctrl_name', 'main\\main'); + $this->_method = 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])) { + $this->_ctrl = \str_replace('/', '\\', $data[$apn]); + } + if (isset($data[$mpn])) { + $this->_method = $data[$mpn]; + } + if(!empty($_SERVER['PATH_INFO'])) { + $routeMap = ZRoute::match(Config::get('route', false), $_SERVER['PATH_INFO']); + if(is_array($routeMap)) { + $this->_ctrl = $routeMap[0]; + $this->_method = $routeMap[1]; + if(!empty($routeMap[2]) && is_array($routeMap[2])) { + //参数优先 + $data = $data + $routeMap[2]; + } + } + } + $this->_params = $data; + $this->_tpl_file = str_replace('\\', DS, $this->_ctrl) . DS . $this->_method . '.php'; + return true; + } + + public function getCtrl() + { + return $this->_ctrl; + } + + public function getMethod() + { + return $this->_method; + } + + public function getParams() + { + return $this->_params; + } + + public function setFd($fd) + { + $this->_fd = $fd; + } + + public function getFd() + { + return $this->_fd; + } + + public function setViewMode($mode) + { + $this->_view_mode = $mode; + } + + public function setTplFile($tpl) + { + $this->_tpl_file = $tpl; + } + + public function display($model) + { + ($viewMode = $this->_view_mode) || ($viewMode = Config::getField('project', 'view_mode', '')); + if(is_array($model) && !empty($model['_view_mode'])) { + $viewMode = $model['_view_mode']; + unset($model['_view_mode']); + } + $this->_view_mode = ''; + if(empty($viewMode)) { + if (ZUtils::isAjax()) { + $viewMode = 'Json'; + } else { + $viewMode = 'Php'; + } + } + + $view = View\Factory::getInstance($viewMode); + if ('Php' === $viewMode) { + if(is_array($model) && !empty($model['_tpl_file'])) { + $view->setTpl($model['_tpl_file']); + unset($model['_tpl_file']); + } else if(!empty($this->_tpl_file)){ + $view->setTpl($this->_tpl_file); + $this->_tpl_file = null; + } else { + throw new \Exception("tpl file empty"); + } + } + $view->setModel($model); + return $view->display(); + + } +} diff --git a/lib/Server/WebSocket.php b/lib/Server/WebSocket.php new file mode 100644 index 0000000..180b117 --- /dev/null +++ b/lib/Server/WebSocket.php @@ -0,0 +1,21 @@ +parse($_REQUEST); + return Core\Route::route($server); + } + +} \ No newline at end of file diff --git a/websocket/apps/ctrl/login.php b/websocket/apps/ctrl/login.php new file mode 100644 index 0000000..eadaeae --- /dev/null +++ b/websocket/apps/ctrl/login.php @@ -0,0 +1,34 @@ +_server = $server; + } + + public function _before() + { + return true; + } + + public function _after() + { + // + } + + public function check() + { + print_r($this->_server->getParams()); + } + + public function reg() + { + return []; + } +} + diff --git a/websocket/template/default/login/reg.php b/websocket/template/default/login/reg.php new file mode 100644 index 0000000..5f87613 --- /dev/null +++ b/websocket/template/default/login/reg.php @@ -0,0 +1,87 @@ + + + + + + + + + + + + +
+
+

zphp websocket chat 注册

+
+
+ + [登录] +
+
+ + \ No newline at end of file diff --git a/websocket/template/default/main/main.php b/websocket/template/default/main/main.php new file mode 100644 index 0000000..e6fc778 --- /dev/null +++ b/websocket/template/default/main/main.php @@ -0,0 +1,51 @@ + + + + + + + + + + + +
+
+

zphp websocket chat

+
+
+ + [注册] +
+
+ + \ No newline at end of file