modify plugin name

This commit is contained in:
2022-02-23 16:32:08 +08:00
parent fa66eef192
commit 99c824c467
37 changed files with 317 additions and 937 deletions
+1 -2
View File
@@ -93,11 +93,10 @@ class ErrorHandler extends Component implements ErrorInterface
$data = Json::to(500, $error[1], $path);
Kiri::app()->error($data, 'error');
$this->logger->error('On error handler', [$data]);
di(EventDispatch::class)->dispatch(new OnAfterRequest());
throw new \ErrorException($error[1], $error[0], 1, $error[2], $error[3]);
}
-117
View File
@@ -1,117 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: admin
* Date: 2019-03-22
* Time: 14:36
*/
declare(strict_types=1);
namespace Kiri\Error;
use Exception;
use Kiri\Abstracts\Component;
use Kiri\Core\Json;
use Kiri;
use Kiri\Annotation\Inject;
use Psr\Log\LoggerInterface;
use Throwable;
/**
* Class Logger
* @package Kiri\Error
* @mixin \Kiri\Abstracts\Logger
*/
class Logger extends Component
{
private array $logs = [];
/**
* inject logger
*
* @var LoggerInterface
*/
#[Inject(LoggerInterface::class)]
public LoggerInterface $logger;
private array $sources = [];
/**
* @param string $application
* @return string
*/
public function getLastError(string $application = 'app'): string
{
return $this->logs[$application] ?? 'Unknown error.';
}
/**
* @param $message
* @param $method
* @return void
*/
public function fail($message, $method)
{
$this->logs[$method] = $message;
}
/**
* @param string $messages
* @param string $method
* @throws Exception
*/
public function write(string $messages, string $method = 'app')
{
if (empty($messages)) {
return;
}
$to_day = date('Y-m-d');
$fileName = storage('server-' . $to_day . '.log', $dirName = 'log/' . ($method ?? 'app'));
file_put_contents($fileName, '[' . date('Y-m-d H:i:s') . ']:' . PHP_EOL . $messages . PHP_EOL);
}
/**
* @param Throwable $exception
* @return mixed
* @throws Exception
*/
public function exception(Throwable $exception): mixed
{
$code = $exception->getCode() == 0 ? 500 : $exception->getCode();
$logger = Kiri::app()->getLogger();
$logger->write(jTraceEx($exception), 'exception');
return Json::to($code, $exception->getMessage(), [
'file' => $exception->getFile(),
'line' => $exception->getLine()
]);
}
/**
* @param string $name
* @param array $arguments
* @return mixed
*/
public function __call(string $name, array $arguments): mixed
{
if (!method_exists($this, $name)) {
return $this->logger->{$name}(...$arguments);
} else {
return $this->{$name}(...$arguments);
}
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace Kiri\Error;
use Kiri\Abstracts\Logger;
use Kiri\Exception\ConfigException;
class StdoutLogger extends Logger implements StdoutLoggerInterface
{
private array $errors = [];
/**
* @param $message
* @param string $model
* @return bool
* @throws ConfigException
*/
public function addError($message, string $model = 'app'): bool
{
$this->error($model, [$message]);
if ($message instanceof \Exception) {
$this->errors[$model] = $message->getMessage();
} else {
$this->errors[$model] = $message;
}
return false;
}
/**
* @param string $model
* @return mixed
*/
public function getLastError(string $model = 'app'): mixed
{
return $this->errors[$model] ?? 'Unknown error.';
}
}
@@ -0,0 +1,26 @@
<?php
namespace Kiri\Error;
use Psr\Log\LoggerInterface;
interface StdoutLoggerInterface extends LoggerInterface
{
/**
* @param $message
* @param string $model
* @return bool
*/
public function addError($message, string $model = 'app'): bool;
/**
* @param string $model
* @return mixed
*/
public function getLastError(string $model = 'app'): mixed;
}