modify plugin name
This commit is contained in:
+44
-26
@@ -8,6 +8,7 @@ use JetBrains\PhpStorm\Pure;
|
|||||||
use Kiri;
|
use Kiri;
|
||||||
use Kiri\Abstracts\Config;
|
use Kiri\Abstracts\Config;
|
||||||
use Kiri\Events\EventDispatch;
|
use Kiri\Events\EventDispatch;
|
||||||
|
use Kiri\Events\EventProvider;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
use Kiri\Message\Constrict\Request;
|
use Kiri\Message\Constrict\Request;
|
||||||
use Kiri\Message\Constrict\RequestInterface;
|
use Kiri\Message\Constrict\RequestInterface;
|
||||||
@@ -15,16 +16,18 @@ use Kiri\Message\Constrict\Response;
|
|||||||
use Kiri\Message\Constrict\ResponseInterface;
|
use Kiri\Message\Constrict\ResponseInterface;
|
||||||
use Kiri\Message\Handler\Abstracts\HttpService;
|
use Kiri\Message\Handler\Abstracts\HttpService;
|
||||||
use Kiri\Message\Handler\Router;
|
use Kiri\Message\Handler\Router;
|
||||||
|
use Kiri\Server\Events\OnBeforeShutdown;
|
||||||
use Kiri\Server\Events\OnServerBeforeStart;
|
use Kiri\Server\Events\OnServerBeforeStart;
|
||||||
use Kiri\Server\Events\OnShutdown;
|
use Kiri\Server\Events\OnShutdown;
|
||||||
|
use Kiri\Server\Events\OnWorkerStart;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
use Swoole\WebSocket\Server as WsServer;
|
||||||
|
use Swoole\Server as SServer;
|
||||||
|
use Swoole\Http\Server as HServer;
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Kiri\Server\Events\OnBeforeShutdown;
|
|
||||||
use Kiri\Events\EventProvider;
|
|
||||||
use Kiri\Server\Events\OnWorkerStart;
|
|
||||||
|
|
||||||
|
|
||||||
defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
|
||||||
@@ -47,8 +50,8 @@ class Server extends HttpService
|
|||||||
* @param ServerManager $manager
|
* @param ServerManager $manager
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
* @param ProcessManager $processManager
|
* @param ProcessManager $processManager
|
||||||
* @param EventDispatch $eventDispatch
|
* @param EventDispatch $dispatch
|
||||||
* @param EventProvider $eventProvider
|
* @param EventProvider $provider
|
||||||
* @param Router $router
|
* @param Router $router
|
||||||
* @param array $config
|
* @param array $config
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -57,8 +60,8 @@ class Server extends HttpService
|
|||||||
public ServerManager $manager,
|
public ServerManager $manager,
|
||||||
public ContainerInterface $container,
|
public ContainerInterface $container,
|
||||||
public ProcessManager $processManager,
|
public ProcessManager $processManager,
|
||||||
public EventDispatch $eventDispatch,
|
public EventDispatch $dispatch,
|
||||||
public EventProvider $eventProvider,
|
public EventProvider $provider,
|
||||||
public Router $router,
|
public Router $router,
|
||||||
array $config = [])
|
array $config = [])
|
||||||
{
|
{
|
||||||
@@ -116,31 +119,46 @@ class Server extends HttpService
|
|||||||
$this->manager->addListener($rpcService['type'], $rpcService['host'], $rpcService['port'], $rpcService['mode'], $rpcService);
|
$this->manager->addListener($rpcService['type'], $rpcService['host'], $rpcService['port'], $rpcService['mode'], $rpcService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->onHotReload();
|
||||||
|
|
||||||
|
pcntl_signal(SIGINT, [$this, 'onSigint']);
|
||||||
|
$processes = array_merge($this->process, Config::get('processes', []));
|
||||||
|
$this->processManager->batch($processes);
|
||||||
|
$this->dispatch->dispatch(new OnServerBeforeStart());
|
||||||
|
$this->manager->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
* @throws ConfigException
|
||||||
|
* @throws ReflectionException
|
||||||
|
*/
|
||||||
|
public function onHotReload(): void
|
||||||
|
{
|
||||||
$reload = Config::get('reload.hot', false);
|
$reload = Config::get('reload.hot', false);
|
||||||
if ($reload !== false) {
|
if ($reload !== false) {
|
||||||
$this->eventProvider->on(OnWorkerStart::class, [$this, 'onWorkerStart']);
|
$this->provider->on(OnWorkerStart::class, [$this, 'onWorkerStart']);
|
||||||
|
|
||||||
$this->process[] = Scaner::class;
|
$this->process[] = Scaner::class;
|
||||||
} else {
|
} else {
|
||||||
$this->onWorkerStart();
|
$this->onWorkerStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
pcntl_signal(SIGINT, function () {
|
|
||||||
try {
|
|
||||||
$this->eventDispatch->dispatch(new OnBeforeShutdown());
|
|
||||||
}catch (\Throwable $exception) {
|
|
||||||
$this->logger->error($exception->getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function onSigint(): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->dispatch->dispatch(new OnBeforeShutdown());
|
||||||
|
} catch (\Throwable $exception) {
|
||||||
|
$this->logger->error($exception->getMessage());
|
||||||
|
} finally {
|
||||||
$this->manager->getServer()->shutdown();
|
$this->manager->getServer()->shutdown();
|
||||||
});
|
}
|
||||||
|
|
||||||
$processes = array_merge($this->process, Config::get('processes', []));
|
|
||||||
|
|
||||||
$this->processManager->batch($processes);
|
|
||||||
|
|
||||||
$this->eventDispatch->dispatch(new OnServerBeforeStart());
|
|
||||||
|
|
||||||
$this->manager->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -170,7 +188,7 @@ class Server extends HttpService
|
|||||||
foreach ($this->manager->sortService($configs['ports'] ?? []) as $config) {
|
foreach ($this->manager->sortService($configs['ports'] ?? []) as $config) {
|
||||||
$this->state->exit($config['port']);
|
$this->state->exit($config['port']);
|
||||||
}
|
}
|
||||||
$this->eventDispatch->dispatch(new OnShutdown());
|
$this->dispatch->dispatch(new OnShutdown());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -200,9 +218,9 @@ class Server extends HttpService
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null
|
* @return HServer|SServer|WsServer|null
|
||||||
*/
|
*/
|
||||||
#[Pure] public function getServer(): \Swoole\Http\Server|\Swoole\Server|\Swoole\WebSocket\Server|null
|
#[Pure] public function getServer(): HServer|SServer|WsServer|null
|
||||||
{
|
{
|
||||||
return $this->manager->getServer();
|
return $this->manager->getServer();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user