This commit is contained in:
xl
2023-06-12 15:31:44 +08:00
parent 599e353a28
commit 8248b418ad
4 changed files with 15 additions and 19 deletions
+2 -3
View File
@@ -134,8 +134,7 @@ class AsyncServer implements ServerInterface
* @param $daemon
* @return void
* @throws ConfigException
* @throws ReflectionException
*/
*/
private function initServer($match, $config, $daemon): void
{
$this->server = new $match($config->host, $config->port, $config->mode, $config->socket);
@@ -145,7 +144,7 @@ class AsyncServer implements ServerInterface
if (!isset($config->events[Constant::SHUTDOWN])) {
$config->events[Constant::SHUTDOWN] = [OnServer::class, 'onShutdown'];
}
Kiri::service()->set('server', $this->server);
Kiri::getDi()->bind(ServerInterface::class, $this->server);
}
+8 -8
View File
@@ -9,6 +9,7 @@ use Kiri\Abstracts\Component;
use Kiri\Server\Contract\OnProcessInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
use Swoole\Coroutine;
use Swoole\Process;
use Psr\Container\ContainerInterface;
@@ -36,15 +37,14 @@ class ProcessManager extends Component
}
/**
* @param OnServerBeforeStart $beforeStart
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface|Exception
*/
/**
* @param OnServerBeforeStart $beforeStart
* @return void
* @throws ReflectionException
*/
public function OnServerBeforeStart(OnServerBeforeStart $beforeStart): void
{
$server = Kiri::service()->get('server');
$server = Kiri::getDi()->get(ServerInterface::class);
foreach ($this->_process as $custom) {
if (Kiri\Di\Context::inCoroutine()) {
Coroutine::create(function () use ($custom) {
@@ -180,7 +180,7 @@ class ProcessManager extends Component
* @param Process $process
* @return void
* @throws Kiri\Exception\ConfigException
* @throws \ReflectionException
* @throws ReflectionException
*/
public function extracted(mixed $custom, Process $process): void
{
+3 -7
View File
@@ -91,14 +91,10 @@ class OnRequest implements OnRequestInterface
$dispatcher = $this->router->query($PsrRequest->getUri()->getPath(), $PsrRequest->getMethod());
$middleware = [];
if (!($dispatcher instanceof Kiri\Router\Base\NotFoundController)) {
$middlewareManager = \Kiri::getDi()->get(MiddlewareManager::class);
$middlewareManager = \Kiri::getDi()->get(MiddlewareManager::class);
$middleware = $middlewareManager->get($dispatcher->getClass(), $dispatcher->getMethod());
$middleware = $middlewareManager->get($dispatcher->getClass(), $dispatcher->getMethod());
}
$PsrResponse = (new HttpRequestHandler($middleware, $dispatcher))->handle($PsrRequest);
$PsrResponse = (new HttpRequestHandler($middleware, $dispatcher))->handle($PsrRequest);
} catch (\Throwable $throwable) {
$PsrResponse = $this->exception->emit($throwable, di(ConstrictResponse::class));
} finally {
+2 -1
View File
@@ -4,6 +4,7 @@ namespace Kiri\Server\Task;
use Kiri\Server\Constant;
use Kiri\Server\ServerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
@@ -73,7 +74,7 @@ class Task implements TaskInterface
public function dispatch(array|string|object $handler, ?int $workerId = null): void
{
/** @var Server $server */
$server = \Kiri::service()->get('server');
$server = \Kiri::getDi()->get(ServerInterface::class);
if (is_null($workerId)) {
$workerId = rand(0, $server->setting[Constant::OPTION_TASK_WORKER_NUM] - 1);
}