改名
This commit is contained in:
+23
-27
@@ -166,7 +166,6 @@ class Server extends Application
|
|||||||
*/
|
*/
|
||||||
private function dispatchCreate($config, $settings)
|
private function dispatchCreate($config, $settings)
|
||||||
{
|
{
|
||||||
$event = Snowflake::get()->event;
|
|
||||||
if (!($this->baseServer instanceof \Swoole\Server)) {
|
if (!($this->baseServer instanceof \Swoole\Server)) {
|
||||||
$class = $this->dispatch($config['type']);
|
$class = $this->dispatch($config['type']);
|
||||||
$this->baseServer = new $class($config['host'], $config['port'], SWOOLE_PROCESS, $config['mode']);
|
$this->baseServer = new $class($config['host'], $config['port'], SWOOLE_PROCESS, $config['mode']);
|
||||||
@@ -177,7 +176,7 @@ class Server extends Application
|
|||||||
if (isset($config['settings']) && is_array($config['settings'])) {
|
if (isset($config['settings']) && is_array($config['settings'])) {
|
||||||
$newListener->set($config['settings']);
|
$newListener->set($config['settings']);
|
||||||
}
|
}
|
||||||
$this->onListenerBind($config, $this->baseServer, $event);
|
$this->onListenerBind($config, $this->baseServer);
|
||||||
}
|
}
|
||||||
return $this->baseServer;
|
return $this->baseServer;
|
||||||
}
|
}
|
||||||
@@ -188,18 +187,11 @@ class Server extends Application
|
|||||||
*/
|
*/
|
||||||
private function bindAnnotation()
|
private function bindAnnotation()
|
||||||
{
|
{
|
||||||
$event = Snowflake::get()->event;
|
|
||||||
if ($this->baseServer instanceof WebSocket) {
|
if ($this->baseServer instanceof WebSocket) {
|
||||||
if ($event->exists(Event::SERVER_WORKER_START, [$this, 'onLoadWebsocketHandler'])) {
|
$this->onLoadWebsocketHandler();
|
||||||
return;
|
|
||||||
}
|
|
||||||
$event->on(Event::SERVER_WORKER_START, [$this, 'onLoadWebsocketHandler']);
|
|
||||||
}
|
}
|
||||||
if ($this->baseServer instanceof Http) {
|
if ($this->baseServer instanceof Http) {
|
||||||
if ($event->exists(Event::SERVER_WORKER_START, [$this, 'onLoadHttpHandler'])) {
|
$this->onLoadHttpHandler();
|
||||||
return;
|
|
||||||
}
|
|
||||||
$event->on(Event::SERVER_WORKER_START, [$this, 'onLoadHttpHandler']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,12 +199,11 @@ class Server extends Application
|
|||||||
/**
|
/**
|
||||||
* @param $config
|
* @param $config
|
||||||
* @param $newListener
|
* @param $newListener
|
||||||
* @param $event
|
|
||||||
* @throws NotFindClassException
|
* @throws NotFindClassException
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function onListenerBind($config, $newListener, $event)
|
private function onListenerBind($config, $newListener)
|
||||||
{
|
{
|
||||||
$this->debug(sprintf('Listener %s::%d', $config['host'], $config['port']));
|
$this->debug(sprintf('Listener %s::%d', $config['host'], $config['port']));
|
||||||
if ($config['type'] == self::HTTP) {
|
if ($config['type'] == self::HTTP) {
|
||||||
@@ -241,39 +232,44 @@ class Server extends Application
|
|||||||
if (in_array($name, $this->listening)) {
|
if (in_array($name, $this->listening)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($name === 'request') {
|
||||||
|
$this->onLoadHttpHandler();
|
||||||
|
}
|
||||||
array_push($this->listening, $name);
|
array_push($this->listening, $name);
|
||||||
$server->on($name, $callback);
|
$server->on($name, $callback);
|
||||||
|
|
||||||
$event = Snowflake::get()->event;
|
|
||||||
if ($name === 'request') {
|
|
||||||
if ($event->exists(Event::SERVER_WORKER_START, [$this, 'onLoadHttpHandler'])) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$event->on(Event::SERVER_WORKER_START, [$this, 'onLoadHttpHandler']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load router handler
|
* Load router handler
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function onLoadHttpHandler()
|
public function onLoadHttpHandler()
|
||||||
{
|
{
|
||||||
$router = Snowflake::get()->router;
|
$event = Snowflake::get()->getEvent();
|
||||||
$router->loadRouterSetting();
|
$router = Snowflake::get()->getRouter();
|
||||||
|
if ($event->exists(Event::SERVER_WORKER_START, [$router, 'loadRouterSetting'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$event->on(Event::SERVER_WORKER_START, [$router, 'loadRouterSetting']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ReflectionException
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function onLoadWebsocketHandler()
|
public function onLoadWebsocketHandler()
|
||||||
{
|
{
|
||||||
$path = APP_PATH . 'app/Websocket';
|
|
||||||
|
|
||||||
/** @var AWebsocket $websocket */
|
/** @var AWebsocket $websocket */
|
||||||
$websocket = Snowflake::get()->annotation->register('websocket', AWebsocket::class);
|
$websocket = Snowflake::get()->annotation->register('websocket', AWebsocket::class);
|
||||||
$websocket->registration_notes($path, 'App\\Websocket');
|
$websocket->namespace = 'App\\Websocket';
|
||||||
|
$websocket->path = APP_PATH . 'app/Websocket';
|
||||||
|
|
||||||
|
$event = Snowflake::get()->event;
|
||||||
|
if ($event->exists(Event::SERVER_WORKER_START, [$websocket, 'registration_notes'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$event->on(Event::SERVER_WORKER_START, [$websocket, 'registration_notes']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,8 +56,14 @@ class Annotation extends BaseAnnotation
|
|||||||
* @param $namespace
|
* @param $namespace
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function registration_notes($path, $namespace)
|
public function registration_notes($path = '', $namespace = '')
|
||||||
{
|
{
|
||||||
|
if (empty($path)) {
|
||||||
|
$path = $this->path;
|
||||||
|
}
|
||||||
|
if (empty($namespace)) {
|
||||||
|
$namespace = $this->namespace;
|
||||||
|
}
|
||||||
$this->scanning(rtrim($path, '/'), $namespace, get_called_class());
|
$this->scanning(rtrim($path, '/'), $namespace, get_called_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user