Skip to content

Commit

Permalink
refactor(pipes): rename AppendKeywordCollectorsPipe to AddKeywordPipe
Browse files Browse the repository at this point in the history
- Rename AppendKeywordCollectorsPipe to AddKeywordPipe
- Update references to the renamed class
  • Loading branch information
guanguans committed Aug 4, 2023
1 parent 179fc90 commit 1766cd0
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 33 deletions.
54 changes: 27 additions & 27 deletions config/exception-notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* This source file is subject to the MIT license that is bundled.
*/

use Guanguans\LaravelExceptionNotify\Pipes\AppendKeywordCollectorsPipe;
use Guanguans\LaravelExceptionNotify\Pipes\LimitLengthReportPipe;
use Guanguans\LaravelExceptionNotify\Pipes\ReplaceStrReportPipe;
use Guanguans\LaravelExceptionNotify\Pipes\ToHtmlPipeReport;
use Guanguans\LaravelExceptionNotify\Pipes\ToMarkdownReportPipe;
use Guanguans\LaravelExceptionNotify\Pipes\TryToFixReportPipe;
use Guanguans\LaravelExceptionNotify\Pipes\AddKeywordPipe;
use Guanguans\LaravelExceptionNotify\Pipes\FixPrettyJsonPipe;
use Guanguans\LaravelExceptionNotify\Pipes\LimitLengthPipe;
use Guanguans\LaravelExceptionNotify\Pipes\ReplaceStrPipe;
use Guanguans\LaravelExceptionNotify\Pipes\ToHtmlPipe;
use Guanguans\LaravelExceptionNotify\Pipes\ToMarkdownPipe;

return [
/**
Expand Down Expand Up @@ -103,8 +103,8 @@
'token' => env('EXCEPTION_NOTIFY_BARK_TOKEN'),
'group' => env('EXCEPTION_NOTIFY_BARK_GROUP', config('app.name')),
'pipes' => [
TryToFixReportPipe::class,
sprintf('%s:%s', LimitLengthReportPipe::class, 1024),
FixPrettyJsonPipe::class,
sprintf('%s:%s', LimitLengthPipe::class, 1024),
],
],

Expand All @@ -118,8 +118,8 @@
'base_uri' => env('EXCEPTION_NOTIFY_CHANIFY_BASE_URI'),
'token' => env('EXCEPTION_NOTIFY_CHANIFY_TOKEN'),
'pipes' => [
TryToFixReportPipe::class,
sprintf('%s:%s', LimitLengthReportPipe::class, 1024),
FixPrettyJsonPipe::class,
sprintf('%s:%s', LimitLengthPipe::class, 1024),
],
],

Expand All @@ -134,9 +134,9 @@
'secret' => env('EXCEPTION_NOTIFY_DINGTALK_SECRET'),
'keyword' => env('EXCEPTION_NOTIFY_DINGTALK_KEYWORD'),
'pipes' => [
sprintf('%s:%s', AppendKeywordCollectorsPipe::class, env('EXCEPTION_NOTIFY_DINGTALK_KEYWORD')),
TryToFixReportPipe::class,
sprintf('%s:%s', LimitLengthReportPipe::class, 20000),
sprintf('%s:%s', AddKeywordPipe::class, env('EXCEPTION_NOTIFY_DINGTALK_KEYWORD')),
FixPrettyJsonPipe::class,
sprintf('%s:%s', LimitLengthPipe::class, 20000),
],
],

Expand All @@ -149,8 +149,8 @@
'driver' => 'discord',
'webhook_url' => env('EXCEPTION_NOTIFY_DISCORD_WEBHOOK_URL'),
'pipes' => [
TryToFixReportPipe::class,
sprintf('%s:%s', LimitLengthReportPipe::class, 2000),
FixPrettyJsonPipe::class,
sprintf('%s:%s', LimitLengthPipe::class, 2000),
],
],

Expand All @@ -165,9 +165,9 @@
'secret' => env('EXCEPTION_NOTIFY_FEISHU_SECRET'),
'keyword' => env('EXCEPTION_NOTIFY_FEISHU_KEYWORD'),
'pipes' => [
sprintf('%s:%s', AppendKeywordCollectorsPipe::class, env('EXCEPTION_NOTIFY_FEISHU_KEYWORD')),
TryToFixReportPipe::class,
sprintf('%s:%s', LimitLengthReportPipe::class, 30720),
sprintf('%s:%s', AddKeywordPipe::class, env('EXCEPTION_NOTIFY_FEISHU_KEYWORD')),
FixPrettyJsonPipe::class,
sprintf('%s:%s', LimitLengthPipe::class, 30720),
],
],

Expand Down Expand Up @@ -197,7 +197,7 @@
'from' => env('EXCEPTION_NOTIFY_MAIL_FROM'),
'to' => env('EXCEPTION_NOTIFY_MAIL_TO'),
'pipes' => [
ToHtmlPipeReport::class,
ToHtmlPipe::class,
],
],

Expand All @@ -211,7 +211,7 @@
'token' => env('EXCEPTION_NOTIFY_PUSHDEER_TOKEN'),
'base_uri' => env('EXCEPTION_NOTIFY_PUSHDEER_BASE_URI'),
'pipes' => [
ToMarkdownReportPipe::class,
ToMarkdownPipe::class,
],
],

Expand All @@ -230,7 +230,7 @@
'environment' => env('EXCEPTION_NOTIFY_QQCHANNELBOT_ENVIRONMENT', 'production'),
'pipes' => [
// 错误码(304003) https://bot.q.qq.com/wiki/develop/api/openapi/error/error.html
sprintf('%s:%s,%s', ReplaceStrReportPipe::class, '.php', '.PHP'),
sprintf('%s:%s,%s', ReplaceStrPipe::class, '.php', '.PHP'),
],
],

Expand All @@ -255,7 +255,7 @@
'webhook_url' => env('EXCEPTION_NOTIFY_SLACK_WEBHOOK_URL'),
'channel' => env('EXCEPTION_NOTIFY_SLACK_CHANNEL'),
'pipes' => [
ToMarkdownReportPipe::class,
ToMarkdownPipe::class,
],
],

Expand All @@ -269,8 +269,8 @@
'token' => env('EXCEPTION_NOTIFY_TELEGRAM_TOKEN'),
'chat_id' => env('EXCEPTION_NOTIFY_TELEGRAM_CHAT_ID'),
'pipes' => [
TryToFixReportPipe::class,
sprintf('%s:%s', LimitLengthReportPipe::class, 4096),
FixPrettyJsonPipe::class,
sprintf('%s:%s', LimitLengthPipe::class, 4096),
],
],

Expand All @@ -283,8 +283,8 @@
'driver' => 'weWork',
'token' => env('EXCEPTION_NOTIFY_WEWORK_TOKEN'),
'pipes' => [
TryToFixReportPipe::class,
sprintf('%s:%s', LimitLengthReportPipe::class, 5120),
FixPrettyJsonPipe::class,
sprintf('%s:%s', LimitLengthPipe::class, 5120),
],
],

Expand All @@ -298,7 +298,7 @@
'type' => env('EXCEPTION_NOTIFY_XIZHI_TYPE', 'single'), // [single, channel]
'token' => env('EXCEPTION_NOTIFY_XIZHI_TOKEN'),
'pipes' => [
ToMarkdownReportPipe::class,
ToMarkdownPipe::class,
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Guanguans\LaravelExceptionNotify\Collectors\ChoreCollector;
use Illuminate\Support\Collection;

class AppendKeywordCollectorsPipe
class AddKeywordPipe
{
public function handle(Collection $collectors, \Closure $next, string $keyword, $key = 'keyword'): string
{
Expand Down
44 changes: 44 additions & 0 deletions src/Pipes/AddValuePipe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?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\Pipes;

use Guanguans\LaravelExceptionNotify\Collectors\ChoreCollector;
use Illuminate\Support\Collection;

class AddValuePipe
{
/**
* @param mixed $value
* @param null|array-key $key
*/
public function handle(Collection $collectors, \Closure $next, $value, $key = null, ?string $collectorName = null): string
{
$collectorName ??= ChoreCollector::name();
$collectorName = (string) ($collectors->has($collectorName) ? $collectorName : array_key_first($collectors->all()));

$collectors = $collectors->transform(
static function (
array $collector,
string $name
) use ($collectorName, $key, $value) {
if ($name === $collectorName) {
null === $key ? $collector[] = $value : $collector[$key] = $value;
}

return $collector;
}
);

return $next($collectors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Guanguans\LaravelExceptionNotify\Support\JsonFixer;
use Illuminate\Support\Collection;

class TryToFixReportPipe
class FixPrettyJsonPipe
{
protected JsonFixer $jsonFixer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Illuminate\Support\Collection;

class LimitLengthReportPipe
class LimitLengthPipe
{
public function handle(Collection $collectors, \Closure $next, int $length): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Illuminate\Support\Collection;

class ReplaceStrReportPipe
class ReplaceStrPipe
{
public function handle(Collection $collectors, \Closure $next, string $search, string $replace): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Illuminate\Support\Collection;

class ToHtmlPipeReport
class ToHtmlPipe
{
public function handle(Collection $collectors, \Closure $next, string $tag = '<pre>%s</pre>'): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Illuminate\Support\Collection;

class ToMarkdownReportPipe
class ToMarkdownPipe
{
public function handle(
Collection $collectors,
Expand Down

0 comments on commit 1766cd0

Please sign in to comment.