This commit is contained in:
as2252258@163.com
2021-09-21 02:46:21 +08:00
parent 0c4af841dd
commit 907942b01a
11 changed files with 404 additions and 378 deletions
@@ -1,6 +1,6 @@
<?php
namespace Server\Worker;
namespace Server\Abstracts;
use Kiri\Kiri;
use Psr\EventDispatcher\EventDispatcherInterface;
@@ -1,6 +1,6 @@
<?php
namespace Server\Worker;
namespace Server\Abstracts;
use Annotation\Annotation;
use Annotation\Inject;
@@ -1,6 +1,6 @@
<?php
namespace Server\Worker;
namespace Server\Abstracts;
use Annotation\Annotation;
use Annotation\Inject;
+11 -1
View File
@@ -5,7 +5,9 @@ namespace Server\Constrict;
use Http\Handler\Context;
use Http\Message\ContentType;
use JetBrains\PhpStorm\Pure;
use Kiri\Abstracts\Config;
use Kiri\Kiri;
use Psr\Http\Message\StreamInterface;
use Http\Message\ServerRequest as RequestMessage;
@@ -27,7 +29,15 @@ class Response implements ResponseInterface
const FILE = 'file';
/**
public function __construct()
{
$contentType = Config::get('response.format',ContentType::JSON);
$this->withContentType($contentType)->withCharset('utf-8');
}
/**
* @param string $name
* @return mixed
*/
+1 -1
View File
@@ -22,7 +22,7 @@ class ResponseEmitter implements Emitter
/**
* @param mixed $response
* @param \Swoole\Http\Response $response
* @param \Http\Message\Response|ResponseInterface $emitter
* @throws \Exception
*/
+2 -1
View File
@@ -3,6 +3,7 @@
namespace Server;
use Http\Message\ContentType;
use Http\Message\Stream;
use Server\Constrict\Response;
use Server\Constrict\ResponseInterface;
@@ -23,7 +24,7 @@ class ExceptionHandlerDispatcher implements ExceptionHandlerInterface
*/
public function emit(Throwable $exception, Response $response): ResponseInterface
{
$response->withContentType('text/html;charset=utf-8');
$response->withContentType(ContentType::HTML)->withCharset('utf-8');
if ($exception->getCode() == 404) {
return $response->withBody(new Stream($exception->getMessage()))
->withStatus(404);
+2 -2
View File
@@ -13,8 +13,8 @@ use Server\Events\OnBeforeWorkerStart;
use Server\Events\OnTaskerStart;
use Server\Events\OnWorkerStart;
use Server\Worker\OnServerWorker;
use Server\Worker\OnWorkerStart as WorkerDispatch;
use Server\Worker\OnTaskerStart as TaskerDispatch;
use Server\Abstracts\OnWorkerStart as WorkerDispatch;
use Server\Abstracts\OnTaskerStart as TaskerDispatch;
use Swoole\Coroutine;
use Swoole\Runtime;
use Symfony\Component\Console\Command\Command;
+2 -3
View File
@@ -9,6 +9,7 @@ use Http\Handler\Context;
use Http\Handler\Abstracts\HandlerManager;
use Http\Handler\Dispatcher;
use Http\Handler\Handler;
use Http\Message\ContentType;
use Http\Message\ServerRequest;
use Http\Message\Stream;
use Http\Handler\Abstracts\MiddlewareManager;
@@ -58,9 +59,7 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect
$PsrResponse = $this->handler($handler, $PsrRequest);
}
} catch (\Throwable $throwable) {
$PsrResponse = $this->response->withStatus($throwable->getCode())
->withContentType(\Http\Message\Response::CONTENT_TYPE_HTML)
->withBody(new Stream(jTraceEx($throwable, null, true)));
$PsrResponse= $this->exceptionHandler->emit($throwable, $this->response);
} finally {
$this->responseEmitter->sender($response, $PsrResponse);
}
-1
View File
@@ -7,7 +7,6 @@ use Exception;
use Kiri\Abstracts\Config;
use Kiri\Core\Help;
use Kiri\Events\EventDispatch;
use Kiri\Kiri;
use Kiri\Runtime;
use Server\Events\OnAfterWorkerStart;
use Server\Events\OnBeforeWorkerStart;