Skip to content

Commit

Permalink
feat(exception-notify): Add ExceptionPreviewCollector
Browse files Browse the repository at this point in the history
- Add ExceptionPreviewCollector to the list of collectors in exception-notify.php
  • Loading branch information
guanguans committed Aug 2, 2023
1 parent 215c445 commit 39bb5cb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/exception-notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions src/Collectors/ExceptionBasicCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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),
];
}
}
30 changes: 30 additions & 0 deletions src/Collectors/ExceptionPreviewCollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

/**
* This file is part of the guanguans/laravel-exception-notify.
*
* (c) guanguans <[email protected]>
*
* 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<mixed>}
*/
public function collect(): array
{
return exceptioncontext::getformattedcontext($this->exception);
}
}
2 changes: 1 addition & 1 deletion src/Collectors/ExceptionTraceCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 39bb5cb

Please sign in to comment.