This commit is contained in:
2021-03-16 14:45:37 +08:00
parent 69830297ea
commit 5824d5626b
+11 -11
View File
@@ -36,11 +36,11 @@ class OnRequest extends Callback
/** /**
* @throws Exception * @throws Exception
*/ */
public function init() // public function init()
{ // {
$this->event = Snowflake::app()->getEvent(); //// $this->event = Snowflake::app()->getEvent();
$this->logger = Snowflake::app()->getLogger(); // $this->logger = Snowflake::app()->getLogger();
} // }
const BEFORE_REQUEST = 'beforeRequest'; const BEFORE_REQUEST = 'beforeRequest';
@@ -59,18 +59,18 @@ class OnRequest extends Callback
/** @var HRequest $request */ /** @var HRequest $request */
[$request, $response] = OnRequest::createContext($request, $response); [$request, $response] = OnRequest::createContext($request, $response);
$this->event->dispatch(self::BEFORE_REQUEST, [$request]); // $this->event->dispatch(Event::EVENT_BEFORE_REQUEST, [$request]);
$result = $request->dispatch(); $result = $request->dispatch();
$this->event->dispatch(self::AFTER_REQUEST, [$request, $result]); // $this->event->dispatch(Event::EVENT_AFTER_REQUEST, [$request, $result]);
return $result; return $result;
} catch (ExitException | Error | \Throwable $exception) { } catch (ExitException | Error | \Throwable $exception) {
return $this->sendErrorMessage($request, $response, $exception); return $this->sendErrorMessage($request, $response, $exception);
} finally { } finally {
$this->event->trigger(Event::SYSTEM_RESOURCE_RELEASES); file(Event::SYSTEM_RESOURCE_RELEASES);
$this->logger->insert(); \logger()->insert();
} }
} }
@@ -98,12 +98,12 @@ class OnRequest extends Callback
protected function sendErrorMessage($sRequest, $sResponse, $exception): bool|string protected function sendErrorMessage($sRequest, $sResponse, $exception): bool|string
{ {
$this->error($exception->getMessage()); $this->error($exception->getMessage());
$this->event->dispatch(self::AFTER_REQUEST, [$sRequest, $exception]);
if ($sResponse instanceof Response) { if ($sResponse instanceof Response) {
[$sRequest, $sResponse] = [HRequest::create($sRequest), HResponse::create($sResponse)]; [$sRequest, $sResponse] = [HRequest::create($sRequest), HResponse::create($sResponse)];
} }
// $this->event->dispatch(Event::EVENT_AFTER_REQUEST, [$sRequest, $exception]);
$headers = $sRequest->headers->get('access-control-request-headers'); $headers = $sRequest->headers->get('access-control-request-headers');
$methods = $sRequest->headers->get('access-control-request-method'); $methods = $sRequest->headers->get('access-control-request-method');