qqq
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user