Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cbd1fb500 |
@@ -67,7 +67,7 @@ class OnRequest implements OnRequestInterface
|
|||||||
public DataGrip $dataGrip)
|
public DataGrip $dataGrip)
|
||||||
{
|
{
|
||||||
$this->responseEmitter = $this->response->emmit;
|
$this->responseEmitter = $this->response->emmit;
|
||||||
$exception = \config('request.exception');
|
$exception = \config('exception.http');
|
||||||
if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) {
|
if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) {
|
||||||
$exception = ExceptionHandlerDispatcher::class;
|
$exception = ExceptionHandlerDispatcher::class;
|
||||||
}
|
}
|
||||||
|
|||||||
+35
-5
@@ -4,7 +4,14 @@ namespace Kiri\Server\Task;
|
|||||||
|
|
||||||
|
|
||||||
use Kiri;
|
use Kiri;
|
||||||
|
use Kiri\Router\Base\ExceptionHandlerDispatcher;
|
||||||
|
use Kiri\Router\DataGrip;
|
||||||
|
use Kiri\Router\Interface\ExceptionHandlerInterface;
|
||||||
use Kiri\Server\Constant;
|
use Kiri\Server\Constant;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\ContainerInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Swoole\Server;
|
use Swoole\Server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,6 +20,25 @@ use Swoole\Server;
|
|||||||
class Task
|
class Task
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public ExceptionHandlerInterface $exception;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ContainerInterface $container
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
public function __construct(public ContainerInterface $container)
|
||||||
|
{
|
||||||
|
$exception = \config('exception.task');
|
||||||
|
if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) {
|
||||||
|
$exception = ExceptionHandlerDispatcher::class;
|
||||||
|
}
|
||||||
|
$this->exception = $this->container->get($exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
* @param Server $server
|
||||||
* @return void
|
* @return void
|
||||||
@@ -53,12 +79,16 @@ class Task
|
|||||||
*/
|
*/
|
||||||
public function onTask(Server $server, int $task_id, int $src_worker_id, mixed $data): mixed
|
public function onTask(Server $server, int $task_id, int $src_worker_id, mixed $data): mixed
|
||||||
{
|
{
|
||||||
$data = json_decode($data, true);
|
try {
|
||||||
if (is_null($data)) {
|
$data = json_decode($data, true);
|
||||||
return null;
|
if (is_null($data)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$data[0] = Kiri::getDi()->get($data[0]);
|
||||||
|
return call_user_func($data, $task_id, $src_worker_id);
|
||||||
|
} catch (\Throwable $throwable) {
|
||||||
|
return $this->exception->emit($throwable, response());
|
||||||
}
|
}
|
||||||
$data[0] = Kiri::getDi()->get($data[0]);
|
|
||||||
return call_user_func($data, $task_id, $src_worker_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user