diff --git a/config/exception-notify.php b/config/exception-notify.php index dcdc15f..a4f1041 100644 --- a/config/exception-notify.php +++ b/config/exception-notify.php @@ -70,6 +70,7 @@ Guanguans\LaravelExceptionNotify\Collectors\PhpInfoCollector::class, Guanguans\LaravelExceptionNotify\Collectors\ChoreCollector::class, Guanguans\LaravelExceptionNotify\Collectors\ExceptionBasicCollector::class, + Guanguans\LaravelExceptionNotify\Collectors\ExceptionPreviewCollector::class, Guanguans\LaravelExceptionNotify\Collectors\ExceptionTraceCollector::class, Guanguans\LaravelExceptionNotify\Collectors\RequestBasicCollector::class, Guanguans\LaravelExceptionNotify\Collectors\RequestHeaderCollector::class, diff --git a/src/Collectors/ExceptionBasicCollector.php b/src/Collectors/ExceptionBasicCollector.php index 30cd0ca..6e73057 100644 --- a/src/Collectors/ExceptionBasicCollector.php +++ b/src/Collectors/ExceptionBasicCollector.php @@ -14,7 +14,6 @@ use Guanguans\LaravelExceptionNotify\Collectors\Concerns\ExceptionAware; use Guanguans\LaravelExceptionNotify\Contracts\ExceptionAwareContract; -use Guanguans\LaravelExceptionNotify\Support\ExceptionContext; class ExceptionBasicCollector extends Collector implements ExceptionAwareContract { @@ -31,7 +30,6 @@ public function collect(): array 'code' => $this->exception->getCode(), 'file' => $this->exception->getfile(), 'line' => $this->exception->getLine(), - 'preview' => exceptioncontext::getformattedcontext($this->exception), ]; } } diff --git a/src/Collectors/ExceptionPreviewCollector.php b/src/Collectors/ExceptionPreviewCollector.php new file mode 100644 index 0000000..ae33108 --- /dev/null +++ b/src/Collectors/ExceptionPreviewCollector.php @@ -0,0 +1,30 @@ + + * + * This source file is subject to the MIT license that is bundled. + */ + +namespace Guanguans\LaravelExceptionNotify\Collectors; + +use Guanguans\LaravelExceptionNotify\Collectors\Concerns\ExceptionAware; +use Guanguans\LaravelExceptionNotify\Contracts\ExceptionAwareContract; +use Guanguans\LaravelExceptionNotify\Support\ExceptionContext; + +class ExceptionPreviewCollector extends Collector implements ExceptionAwareContract +{ + use ExceptionAware; + + /** + * @return array{class: class-string<\Throwable>|true, message: string, code: int|string, file: string, line: int, preview: array} + */ + public function collect(): array + { + return exceptioncontext::getformattedcontext($this->exception); + } +} diff --git a/src/Collectors/ExceptionTraceCollector.php b/src/Collectors/ExceptionTraceCollector.php index f081d59..9e551ab 100644 --- a/src/Collectors/ExceptionTraceCollector.php +++ b/src/Collectors/ExceptionTraceCollector.php @@ -25,7 +25,7 @@ class ExceptionTraceCollector extends Collector implements ExceptionAwareContrac */ public function collect(): array { - return collect(explode("\n", $this->exception->getTraceAsString())) + return collect(explode(PHP_EOL, $this->exception->getTraceAsString())) ->filter(static fn ($trace) => ! Str::contains($trace, 'vendor')) ->all(); }