Skip to content

Commit 26bf392

Browse files
committed
Refactor the channels and add log channel
1 parent 8c1654c commit 26bf392

12 files changed

+183
-50
lines changed

src/Channels/ChanifyChannel.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,29 @@
1010

1111
namespace Guanguans\LaravelExceptionNotify\Channels;
1212

13+
use Guanguans\Notify\Clients\ChanifyClient;
1314
use Guanguans\Notify\Messages\Chanify\TextMessage;
1415

1516
class ChanifyChannel extends Channel
1617
{
18+
/**
19+
* @var \Guanguans\Notify\Clients\ChanifyClient
20+
*/
21+
protected $client;
22+
23+
public function __construct(ChanifyClient $client)
24+
{
25+
$this->client = $client;
26+
}
27+
28+
public function report(string $report)
29+
{
30+
return $this
31+
->client
32+
->setMessage($this->createMessage($report))
33+
->send();
34+
}
35+
1736
protected function createMessage(string $report)
1837
{
1938
return new TextMessage([

src/Channels/Channel.php

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,14 @@
1212

1313
use Guanguans\LaravelExceptionNotify\Contracts\Channel as ChannelContract;
1414
use Guanguans\LaravelExceptionNotify\Support\Traits\CreateStatic;
15-
use Guanguans\Notify\Clients\Client;
16-
use Illuminate\Pipeline\Pipeline;
1715
use Illuminate\Support\Str;
1816

1917
abstract class Channel implements ChannelContract
2018
{
2119
use CreateStatic;
2220

23-
/**
24-
* @var \Guanguans\Notify\Clients\Client
25-
*/
26-
protected $client;
27-
28-
public function __construct(Client $client)
29-
{
30-
$this->client = $client;
31-
}
32-
33-
public function report(string $report)
34-
{
35-
$report = $this->handleReport($report);
36-
37-
return $this
38-
->client
39-
->setMessage($this->createMessage($report))
40-
->send();
41-
}
42-
43-
abstract protected function createMessage(string $report);
44-
45-
protected function handleReport(string $report): string
46-
{
47-
return (new Pipeline(app()))
48-
->send($report)
49-
->through($this->getPipeline())
50-
->then(function ($passable) {
51-
return $passable;
52-
});
53-
}
54-
5521
public function getName(): string
5622
{
5723
return Str::lcfirst(Str::beforeLast(class_basename($this), 'Channel'));
5824
}
59-
60-
public function getPipeline(): array
61-
{
62-
return array_merge(
63-
config('exception-notify.pipeline', []),
64-
config(sprintf('exception-notify.channels.%s.pipeline', $this->getName()), [])
65-
);
66-
}
6725
}

src/Channels/DingTalkChannel.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,29 @@
1010

1111
namespace Guanguans\LaravelExceptionNotify\Channels;
1212

13+
use Guanguans\Notify\Clients\DingTalkClient;
1314
use Guanguans\Notify\Messages\DingTalk\TextMessage;
1415

1516
class DingTalkChannel extends Channel
1617
{
18+
/**
19+
* @var \Guanguans\Notify\Clients\DingTalkClient
20+
*/
21+
protected $client;
22+
23+
public function __construct(DingTalkClient $client)
24+
{
25+
$this->client = $client;
26+
}
27+
28+
public function report(string $report)
29+
{
30+
return $this
31+
->client
32+
->setMessage($this->createMessage($report))
33+
->send();
34+
}
35+
1736
protected function createMessage(string $report)
1837
{
1938
return new TextMessage(['content' => $report]);

src/Channels/FeiShuChannel.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,29 @@
1010

1111
namespace Guanguans\LaravelExceptionNotify\Channels;
1212

13+
use Guanguans\Notify\Clients\FeiShuClient;
1314
use Guanguans\Notify\Messages\FeiShu\TextMessage;
1415

1516
class FeiShuChannel extends Channel
1617
{
18+
/**
19+
* @var \Guanguans\Notify\Clients\FeiShuClient
20+
*/
21+
protected $client;
22+
23+
public function __construct(FeiShuClient $client)
24+
{
25+
$this->client = $client;
26+
}
27+
28+
public function report(string $report)
29+
{
30+
return $this
31+
->client
32+
->setMessage($this->createMessage($report))
33+
->send();
34+
}
35+
1736
protected function createMessage(string $report)
1837
{
1938
return new TextMessage($report);

src/Channels/LogChannel.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the guanguans/laravel-exception-notify.
5+
*
6+
* (c) guanguans <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled.
9+
*/
10+
11+
namespace Guanguans\LaravelExceptionNotify\Channels;
12+
13+
use Illuminate\Support\Facades\Log;
14+
15+
class LogChannel extends Channel
16+
{
17+
public function report(string $report)
18+
{
19+
Log::error($report);
20+
}
21+
}

src/Channels/MailChannel.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,29 @@
1010

1111
namespace Guanguans\LaravelExceptionNotify\Channels;
1212

13+
use Guanguans\Notify\Clients\MailerClient;
1314
use Guanguans\Notify\Messages\EmailMessage;
1415

1516
class MailChannel extends Channel
1617
{
18+
/**
19+
* @var \Guanguans\Notify\Clients\MailerClient
20+
*/
21+
protected $client;
22+
23+
public function __construct(MailerClient $client)
24+
{
25+
$this->client = $client;
26+
}
27+
28+
public function report(string $report)
29+
{
30+
return $this
31+
->client
32+
->setMessage($this->createMessage($report))
33+
->send();
34+
}
35+
1736
protected function createMessage(string $report)
1837
{
1938
return EmailMessage::create()

src/Channels/NullChannel.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,10 @@
1010

1111
namespace Guanguans\LaravelExceptionNotify\Channels;
1212

13-
use Guanguans\LaravelExceptionNotify\Contracts\Channel;
14-
15-
class NullChannel implements Channel
13+
class NullChannel extends Channel
1614
{
17-
public function getName(): string
18-
{
19-
return 'null';
20-
}
21-
2215
public function report(string $report)
2316
{
17+
// noop
2418
}
2519
}

src/Channels/ServerChanChannel.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,29 @@
1010

1111
namespace Guanguans\LaravelExceptionNotify\Channels;
1212

13+
use Guanguans\Notify\Clients\ServerChanClient;
1314
use Guanguans\Notify\Messages\ServerChanMessage;
1415

1516
class ServerChanChannel extends Channel
1617
{
18+
/**
19+
* @var \Guanguans\Notify\Clients\ServerChanClient
20+
*/
21+
protected $client;
22+
23+
public function __construct(ServerChanClient $client)
24+
{
25+
$this->client = $client;
26+
}
27+
28+
public function report(string $report)
29+
{
30+
return $this
31+
->client
32+
->setMessage($this->createMessage($report))
33+
->send();
34+
}
35+
1736
protected function createMessage(string $content)
1837
{
1938
return new ServerChanMessage(config('exception-notify.title'), $content);

src/Channels/WeWorkChannel.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,29 @@
1010

1111
namespace Guanguans\LaravelExceptionNotify\Channels;
1212

13+
use Guanguans\Notify\Clients\WeWorkClient;
1314
use Guanguans\Notify\Messages\WeWork\TextMessage;
1415

1516
class WeWorkChannel extends Channel
1617
{
18+
/**
19+
* @var \Guanguans\Notify\Clients\WeWorkClient
20+
*/
21+
protected $client;
22+
23+
public function __construct(WeWorkClient $client)
24+
{
25+
$this->client = $client;
26+
}
27+
28+
public function report(string $report)
29+
{
30+
return $this
31+
->client
32+
->setMessage($this->createMessage($report))
33+
->send();
34+
}
35+
1736
protected function createMessage(string $report)
1837
{
1938
return new TextMessage(['content' => $report]);

src/Channels/XiZhiChannel.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,29 @@
1010

1111
namespace Guanguans\LaravelExceptionNotify\Channels;
1212

13+
use Guanguans\Notify\Clients\XiZhiClient;
1314
use Guanguans\Notify\Messages\XiZhiMessage;
1415

1516
class XiZhiChannel extends Channel
1617
{
18+
/**
19+
* @var \Guanguans\Notify\Clients\XiZhiClient
20+
*/
21+
protected $client;
22+
23+
public function __construct(XiZhiClient $client)
24+
{
25+
$this->client = $client;
26+
}
27+
28+
public function report(string $report)
29+
{
30+
return $this
31+
->client
32+
->setMessage($this->createMessage($report))
33+
->send();
34+
}
35+
1736
protected function createMessage(string $content)
1837
{
1938
return new XiZhiMessage(config('exception-notify.title'), $content);

0 commit comments

Comments
 (0)