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