modify plugin name

This commit is contained in:
2022-06-22 10:53:59 +08:00
parent f20e695919
commit f139f32c85
2 changed files with 32 additions and 9 deletions
+3 -1
View File
@@ -5,13 +5,15 @@ namespace PHPSTORM_META {
// Reflect
use Kiri\Di\Container;
use Kiri\Di\ContainerInterface;
use Psr\Container\ContainerInterface as SC;
override(ContainerInterface::get(0), map('@'));
override(SC::get(0), map('@'));
override(Container::get(0), map('@'));
override(Container::make(0), map('@'));
override(Container::create(0), map('@'));
// override(\Hyperf\Utils\Context::get(0), map('@'));
// override(\make(0), map('@'));
override(\make(0), map('@'));
override(\di(0), map('@'));
override(\duplicate(0), map('@'));
+29 -8
View File
@@ -13,9 +13,14 @@ 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;
/**
* Class ErrorHandler
@@ -31,6 +36,14 @@ class ErrorHandler extends Component implements ErrorInterface
public string $category = 'app';
/**
* @var EventDispatch
*/
#[Inject(EventDispatch::class)]
public EventDispatch $dispatch;
/**
* 错误处理注册
*/
@@ -42,9 +55,13 @@ class ErrorHandler extends Component implements ErrorInterface
}
/**
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
* @throws Exception
*/
public function shutdown()
public function shutdown(): void
{
$lastError = error_get_last();
if (empty($lastError) || $lastError['type'] !== E_ERROR) {
@@ -57,6 +74,8 @@ class ErrorHandler extends Component implements ErrorInterface
$message = array_shift($messages);
$this->dispatch->dispatch(new OnShutdown());
$this->sendError($message, $lastError['file'], $lastError['line']);
}
@@ -64,22 +83,26 @@ class ErrorHandler extends Component implements ErrorInterface
/**
* @param \Throwable $exception
*
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
* @throws Exception
*/
public function exceptionHandler(\Throwable $exception)
{
$this->category = 'exception';
di(EventDispatch::class)->dispatch(new OnAfterRequest());
$this->dispatch->dispatch(new OnAfterRequest());
$this->sendError($exception->getMessage(), $exception->getFile(), $exception->getLine());
}
/**
* @throws Exception
*
* 以异常形式抛出错误,防止执行后续程序
* @throws \ErrorException
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function errorHandler()
{
@@ -95,7 +118,7 @@ class ErrorHandler extends Component implements ErrorInterface
$this->logger->error('On error handler', [$data]);
di(EventDispatch::class)->dispatch(new OnAfterRequest());
$this->dispatch->dispatch(new OnAfterRequest());
throw new \ErrorException($error[1], $error[0], 1, $error[2], $error[3]);
}
@@ -116,8 +139,6 @@ class ErrorHandler extends Component implements ErrorInterface
file_put_contents('php://output', $data . PHP_EOL, FILE_APPEND);
write($data, $this->category);
return $data;
}