-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Notifies.php
99 lines (86 loc) · 2.16 KB
/
Notifies.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Cerbero\NotifiableException;
use Cerbero\NotifiableException\Notifications\ErrorOccurred;
use Illuminate\Notifications\AnonymousNotifiable;
/**
* Trait to let exceptions notify their errors.
*
*/
trait Notifies
{
/**
* Define how the current exception should be reported by the exception handler
*
* @return void
*/
public function report()
{
$this->notify();
}
/**
* Notify the current exception.
*
* @return void
*/
public function notify()
{
/** @var \Cerbero\NotifiableException\Notifiable $this */
$notification = new ErrorOccurred($this);
$routes = $this->getRoutesToNotify();
foreach ($routes as $channel => $channelRoutes) {
$channelRoutes = array_unique((array) $channelRoutes);
foreach ($channelRoutes as $route) {
(new AnonymousNotifiable)->route($channel, $route)->notify($notification);
}
}
}
/**
* Retrieve all the routes to send notification to.
*
* @return array
*/
protected function getRoutesToNotify(): array
{
if ($this->overridesRoutes()) {
return $this->getCustomRoutes();
}
$defaultRoutes = config('notifiable_exception.default_routes');
return array_merge_recursive($defaultRoutes, $this->getCustomRoutes());
}
/**
* Determine whether the current exception routes should override the default ones.
*
* @return bool
*/
protected function overridesRoutes(): bool
{
return false;
}
/**
* Retrieve the custom notification routes keyed by the channel alias
*
* @return array
*/
protected function getCustomRoutes(): array
{
return [];
}
/**
* Retrieve the message for each channel keyed by the channel alias
*
* @return array
*/
public function getMessages(): array
{
return [];
}
/**
* Retrieve the custom channel class names keyed by the channel alias
*
* @return array
*/
public function getCustomChannels(): array
{
return [];
}
}