Skip to content

Commit 653189d

Browse files
committed
Optimize
1 parent 33fbf7e commit 653189d

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

src/CollectorManager.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Illuminate\Support\Collection;
1717
use Illuminate\Support\Fluent;
1818
use Stringable;
19+
use Throwable;
1920

2021
class CollectorManager extends Fluent implements Stringable
2122
{
@@ -40,18 +41,25 @@ public function offsetSet($offset, $value): void
4041
$this->attributes[$offset] = $value;
4142
}
4243

43-
public function __toString()
44+
public function toReport(Throwable $e): string
4445
{
4546
return (string) collect($this)
46-
->transform(function (Collector $collector) {
47-
$collector instanceof ExceptionAware and $collector->setException(app('exception.notify.exception'));
47+
->transform(function (Collector $collector) use ($e) {
48+
$collector instanceof ExceptionAware and $collector->setException($e);
4849

4950
return $collector;
5051
})
5152
->pipe(function (Collection $collectors): string {
52-
return $collectors->reduce(function (string $carry, Collector $collector) {
53+
$report = $collectors->reduce(function (string $carry, Collector $collector) {
5354
return $carry.PHP_EOL.sprintf('%s: %s', $collector->getName(), $collector);
5455
}, '');
56+
57+
return trim($report);
5558
});
5659
}
60+
61+
public function __toString()
62+
{
63+
return $this->toReport(app('exception.notify.exception'));
64+
}
5765
}

src/ExceptionNotifyManager.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use Guanguans\LaravelExceptionNotify\Jobs\ReportExceptionJob;
3131
use Guanguans\Notify\Factory;
3232
use Illuminate\Contracts\Container\Container;
33-
use Illuminate\Contracts\Queue\ShouldQueue;
3433
use Illuminate\Support\Arr;
3534
use Illuminate\Support\Manager;
3635
use Illuminate\Support\Str;
@@ -85,18 +84,6 @@ protected function registerException(Throwable $e)
8584
$this->container->instance('exception.notify.exception', $e);
8685
}
8786

88-
protected function registerReportExceptionJobMethod()
89-
{
90-
$this->container->bindMethod(
91-
sprintf('%s@handle', ReportExceptionJob::class),
92-
function (ShouldQueue $job, Container $container) {
93-
$report = (string) $container->make(CollectorManager::class);
94-
95-
return $job->handle($report);
96-
}
97-
);
98-
}
99-
10087
protected function dispatchReportExceptionJob()
10188
{
10289
$report = (string) $this->container->make(CollectorManager::class);

src/Jobs/ReportExceptionJob.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Guanguans\LaravelExceptionNotify\Contracts\Channel;
1414
use Guanguans\LaravelExceptionNotify\Events\ReportedEvent;
1515
use Guanguans\LaravelExceptionNotify\Events\ReportingEvent;
16-
use Guanguans\LaravelExceptionNotify\Pipelines\TrimPipeline;
1716
use Guanguans\LaravelExceptionNotify\Support\Traits\CreateStatic;
1817
use Illuminate\Bus\Queueable;
1918
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -79,10 +78,7 @@ public function handle()
7978

8079
protected function getChannelPipeline(): array
8180
{
82-
return array_merge(
83-
[TrimPipeline::class],
84-
config(sprintf('exception-notify.channels.%s.pipeline', $this->channel->getName()), [])
85-
);
81+
return config(sprintf('exception-notify.channels.%s.pipeline', $this->channel->getName()), []);
8682
}
8783

8884
protected function pipelineReport(string $report): string

0 commit comments

Comments
 (0)