变更
This commit is contained in:
@@ -14,14 +14,11 @@ use Exception;
|
||||
use Kiri;
|
||||
use Kiri\Abstracts\Component;
|
||||
use Kiri\Core\Json;
|
||||
use Kiri\Annotation\Inject;
|
||||
use Kiri\Events\EventDispatch;
|
||||
use Kiri\Message\Events\OnAfterRequest;
|
||||
use Kiri\Message\Handler\Formatter\IFormatter;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Kiri\Server\Events\OnShutdown;
|
||||
use ReflectionException;
|
||||
use Kiri\Di\Inject\Container;
|
||||
|
||||
/**
|
||||
* Class ErrorHandler
|
||||
@@ -32,10 +29,6 @@ use ReflectionException;
|
||||
class ErrorHandler extends Component implements ErrorInterface
|
||||
{
|
||||
|
||||
/** @var ?IFormatter $message */
|
||||
private ?IFormatter $message = NULL;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -45,7 +38,7 @@ class ErrorHandler extends Component implements ErrorInterface
|
||||
/**
|
||||
* @var EventDispatch
|
||||
*/
|
||||
#[Inject(EventDispatch::class)]
|
||||
#[Container(EventDispatch::class)]
|
||||
public EventDispatch $dispatch;
|
||||
|
||||
|
||||
@@ -114,7 +107,7 @@ class ErrorHandler extends Component implements ErrorInterface
|
||||
|
||||
$message = array_shift($messages);
|
||||
|
||||
$this->dispatch->dispatch(new OnShutdown());
|
||||
$this->dispatch->dispatch(new Kiri\Events\OnSystemError());
|
||||
|
||||
$this->sendError($message, $lastError['file'], $lastError['line']);
|
||||
}
|
||||
@@ -125,14 +118,13 @@ class ErrorHandler extends Component implements ErrorInterface
|
||||
*
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function exceptionHandler(\Throwable $exception)
|
||||
{
|
||||
$this->category = 'exception';
|
||||
|
||||
$this->dispatch->dispatch(new OnAfterRequest());
|
||||
$this->dispatch->dispatch(new Kiri\Events\OnSystemError());
|
||||
|
||||
$this->sendError($exception->getMessage(), $exception->getFile(), $exception->getLine());
|
||||
}
|
||||
@@ -158,7 +150,7 @@ class ErrorHandler extends Component implements ErrorInterface
|
||||
|
||||
$this->logger->error('On error handler', [$data]);
|
||||
|
||||
$this->dispatch->dispatch(new OnAfterRequest());
|
||||
$this->dispatch->dispatch(new Kiri\Events\OnSystemError());
|
||||
|
||||
throw new \ErrorException($error[1], $error[0], 1, $error[2], $error[3]);
|
||||
}
|
||||
@@ -181,24 +173,7 @@ class ErrorHandler extends Component implements ErrorInterface
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getErrorMessage(): mixed
|
||||
{
|
||||
$message = $this->message;
|
||||
$this->message = NULL;
|
||||
return $message->getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getAsError(): bool
|
||||
{
|
||||
return $this->message !== NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Kiri\Error;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Kiri\Message\Aspect\OnAspectInterface;
|
||||
use Kiri\Message\Aspect\OnJoinPointInterface;
|
||||
use Kiri\Message\Constrict\RequestInterface;
|
||||
use Kiri;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Class LoggerAspect
|
||||
* @package Kiri\Error
|
||||
*/
|
||||
class LoggerAspect implements OnAspectInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @param OnJoinPointInterface $joinPoint
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function process(OnJoinPointInterface $joinPoint): mixed
|
||||
{
|
||||
$time = microtime(true);
|
||||
|
||||
$response = $joinPoint->process();
|
||||
|
||||
$this->print_runtime($time);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $startTime
|
||||
* @throws Exception
|
||||
*/
|
||||
private function print_runtime($startTime)
|
||||
{
|
||||
$request = Kiri::getDi()->get(RequestInterface::class);
|
||||
$runTime = round(microtime(true) - $startTime, 6);
|
||||
|
||||
$logger = Kiri::getDi()->get(LoggerInterface::class);
|
||||
$logger->debug(sprintf('run %s use time %6f', $request->getUri()->__toString(), $runTime));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Error;
|
||||
|
||||
use Kiri\Abstracts\Logger;
|
||||
|
||||
Reference in New Issue
Block a user