modify plugin name

This commit is contained in:
2022-03-03 18:11:24 +08:00
parent 84eac26247
commit 8037bfa1b9
+22 -17
View File
@@ -7,7 +7,6 @@ use Exception;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use Kiri; use Kiri;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Annotation\Inject;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Message\Constrict\Request; use Kiri\Message\Constrict\Request;
@@ -19,6 +18,7 @@ use Kiri\Message\Handler\Router;
use Kiri\Server\Events\OnServerBeforeStart; use Kiri\Server\Events\OnServerBeforeStart;
use Kiri\Server\Events\OnShutdown; use Kiri\Server\Events\OnShutdown;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use ReflectionException; use ReflectionException;
use Swoole\Coroutine; use Swoole\Coroutine;
@@ -33,21 +33,29 @@ defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
class Server extends HttpService class Server extends HttpService
{ {
private array $process = [ private array $process = [];
];
private mixed $daemon = 0; private mixed $daemon = 0;
/** /**
* @var State * @param State $state
* @param ServerManager $manager
* @param ContainerInterface $container
* @param array $config
* @throws Exception
*/ */
#[Inject(State::class)] public function __construct(public State $state,
public State $state; public ServerManager $manager,
public ContainerInterface $container,
public ProcessManager $processManager,
public ServerManager $manager; public EventDispatch $eventDispatch,
public Router $router,
array $config = [])
{
parent::__construct($config);
}
/** /**
@@ -58,12 +66,9 @@ class Server extends HttpService
*/ */
public function init() public function init()
{ {
$container = $this->getContainer(); $this->container->mapping(ResponseInterface::class, Response::class);
$this->container->mapping(RequestInterface::class, Request::class);
$container->mapping(ResponseInterface::class, Response::class);
$container->mapping(RequestInterface::class, Request::class);
$this->manager = $container->get(ServerManager::class);
$enable_coroutine = Config::get('servers.settings.enable_coroutine', false); $enable_coroutine = Config::get('servers.settings.enable_coroutine', false);
if ($enable_coroutine != true) { if ($enable_coroutine != true) {
return; return;
@@ -106,11 +111,11 @@ class Server extends HttpService
$processes = array_merge($this->process, Config::get('processes', [])); $processes = array_merge($this->process, Config::get('processes', []));
$this->getContainer()->get(ProcessManager::class)->batch($processes); $this->processManager->batch($processes);
$this->eventDispatch->dispatch(new OnServerBeforeStart()); $this->eventDispatch->dispatch(new OnServerBeforeStart());
$this->getContainer()->get(Router::class)->scan_build_route(); $this->router->scan_build_route();
$this->manager->start(); $this->manager->start();
} }
@@ -130,7 +135,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->getContainer()->get(EventDispatch::class)->dispatch(new OnShutdown()); $this->eventDispatch->dispatch(new OnShutdown());
} }