变更
This commit is contained in:
+21
-2
@@ -10,6 +10,8 @@ use Kiri\Error\StdoutLoggerInterface;
|
|||||||
use Kiri\Events\EventDispatch;
|
use Kiri\Events\EventDispatch;
|
||||||
use Kiri\Events\EventProvider;
|
use Kiri\Events\EventProvider;
|
||||||
use Kiri\Exception\ConfigException;
|
use Kiri\Exception\ConfigException;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Swoole\Process;
|
use Swoole\Process;
|
||||||
|
|
||||||
if (!function_exists('make')) {
|
if (!function_exists('make')) {
|
||||||
@@ -835,7 +837,7 @@ if (!function_exists('storage')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!function_exists('event')) {
|
if (!function_exists('on')) {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -844,7 +846,7 @@ if (!function_exists('event')) {
|
|||||||
* @param bool $isAppend
|
* @param bool $isAppend
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function event($name, $callback, bool $isAppend = TRUE)
|
function on($name, $callback, bool $isAppend = TRUE): void
|
||||||
{
|
{
|
||||||
$pro = di(EventProvider::class);
|
$pro = di(EventProvider::class);
|
||||||
$pro->on($name, $callback, 0);
|
$pro->on($name, $callback, 0);
|
||||||
@@ -1199,6 +1201,23 @@ if (!function_exists('success')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!function_exists('event')) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param object $object
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @throws ContainerExceptionInterface
|
||||||
|
* @throws NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
function event(object $object): void
|
||||||
|
{
|
||||||
|
Kiri::getDi()->get(EventDispatch::class)->dispatch($object);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!function_exists('throwable')) {
|
if (!function_exists('throwable')) {
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class ErrorHandler extends Component implements ErrorInterface
|
|||||||
/**
|
/**
|
||||||
* @param array|Closure|null $callback
|
* @param array|Closure|null $callback
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function registerShutdownHandler(null|array|Closure $callback): void
|
public function registerShutdownHandler(null|array|Closure $callback): void
|
||||||
{
|
{
|
||||||
@@ -102,7 +103,7 @@ class ErrorHandler extends Component implements ErrorInterface
|
|||||||
|
|
||||||
$message = array_shift($messages);
|
$message = array_shift($messages);
|
||||||
|
|
||||||
Kiri::getDi()->get(EventDispatch::class)->dispatch(new Kiri\Events\OnSystemError());
|
event(new Kiri\Events\OnSystemError());
|
||||||
|
|
||||||
$this->sendError($message, $lastError['file'], $lastError['line']);
|
$this->sendError($message, $lastError['file'], $lastError['line']);
|
||||||
}
|
}
|
||||||
@@ -115,11 +116,11 @@ class ErrorHandler extends Component implements ErrorInterface
|
|||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function exceptionHandler(\Throwable $exception)
|
public function exceptionHandler(\Throwable $exception): void
|
||||||
{
|
{
|
||||||
$this->category = 'exception';
|
$this->category = 'exception';
|
||||||
|
|
||||||
Kiri::getDi()->get(EventDispatch::class)->dispatch(new Kiri\Events\OnSystemError());
|
event(new Kiri\Events\OnSystemError());
|
||||||
|
|
||||||
$this->sendError($exception->getMessage(), $exception->getFile(), $exception->getLine());
|
$this->sendError($exception->getMessage(), $exception->getFile(), $exception->getLine());
|
||||||
}
|
}
|
||||||
@@ -143,9 +144,9 @@ class ErrorHandler extends Component implements ErrorInterface
|
|||||||
|
|
||||||
$data = Json::jsonFail($error[1], 500, $path);
|
$data = Json::jsonFail($error[1], 500, $path);
|
||||||
|
|
||||||
\Kiri::getLogger()->error('On error handler', [$data]);
|
error('On error handler', [$data]);
|
||||||
|
|
||||||
Kiri::getDi()->get(EventDispatch::class)->dispatch(new Kiri\Events\OnSystemError());
|
event(new Kiri\Events\OnSystemError());
|
||||||
|
|
||||||
throw new \ErrorException($error[1], $error[0], 1, $error[2], $error[3]);
|
throw new \ErrorException($error[1], $error[0], 1, $error[2], $error[3]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user