File tree Expand file tree Collapse file tree 10 files changed +97
-12
lines changed
Expand file tree Collapse file tree 10 files changed +97
-12
lines changed Original file line number Diff line number Diff line change 3232 "autoload" : {
3333 "psr-4" : {
3434 "Spatie\\ UptimeMonitor\\ " : " src"
35- }
35+ },
36+ "files" : [
37+ " src/Helpers/functions.php"
38+ ]
3639 },
3740 "autoload-dev" : {
3841 "psr-4" : {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Spatie \UptimeMonitor \Commands ;
4+
5+ use Illuminate \Console \Command ;
6+ use Spatie \UptimeMonitor \Helpers \ConsoleOutput ;
7+ use Symfony \Component \Console \Input \InputInterface ;
8+ use Symfony \Component \Console \Output \OutputInterface ;
9+
10+ abstract class BaseCommand extends Command
11+ {
12+ /**
13+ * @param \Symfony\Component\Console\Input\InputInterface $input
14+ * @param \Symfony\Component\Console\Output\OutputInterface $output
15+ *
16+ * @return int
17+ */
18+ public function run (InputInterface $ input , OutputInterface $ output )
19+ {
20+ app (ConsoleOutput::class)->setOutput ($ this );
21+
22+ return parent ::run ($ input , $ output );
23+ }
24+ }
Original file line number Diff line number Diff line change 22
33namespace Spatie \UptimeMonitor \Commands ;
44
5- use Illuminate \Console \Command ;
65use Spatie \UptimeMonitor \Models \UptimeMonitor ;
76use Spatie \UptimeMonitor \Services \PingMonitors \UptimeMonitorCollection ;
87
9- class CheckUptimeMonitors extends Command
8+ class CheckUptimeMonitors extends BaseCommand
109{
1110 /**
1211 * The name and signature of the console command.
Original file line number Diff line number Diff line change 33namespace Spatie \UptimeMonitor \Events ;
44
55use Illuminate \Contracts \Queue \ShouldQueue ;
6+ use Spatie \UptimeMonitor \Models \UptimeMonitor ;
67
78class SiteUp implements ShouldQueue
89{
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Spatie \UptimeMonitor \Helpers ;
4+
5+ class ConsoleOutput
6+ {
7+ /** @var \Illuminate\Console\OutputStyle */
8+ protected $ output ;
9+
10+ /**
11+ * @param $output
12+ */
13+ public function setOutput ($ output )
14+ {
15+ $ this ->output = $ output ;
16+ }
17+
18+ public function __call (string $ method , array $ arguments )
19+ {
20+ $ consoleOutput = app (static ::class);
21+
22+ if (! $ consoleOutput ->output ) {
23+ return ;
24+ }
25+
26+ $ consoleOutput ->output ->$ method ($ arguments [0 ]);
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Spatie \UptimeMonitor \Helpers ;
4+
5+ class Format
6+ {
7+ public static function emoji (bool $ bool ): string
8+ {
9+ if ($ bool ) {
10+ return "\u{2705}" ;
11+ }
12+
13+ return "\u{274C}" ;
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Spatie \UptimeMonitor \Helpers \ConsoleOutput ;
4+
5+
6+
7+ function consoleOutput (): ConsoleOutput
8+ {
9+ return app (ConsoleOutput::class);
10+ }
Original file line number Diff line number Diff line change @@ -22,11 +22,16 @@ public function __construct(Repository $config)
2222 public function subscribe (Dispatcher $ events )
2323 {
2424 $ events ->listen ($ this ->allUptimeMonitorEventClasses (), function ($ event ) {
25- $ notifiable = $ this ->determineNotifiable ();
2625
2726 $ notification = $ this ->determineNotification ($ event );
2827
28+ if (! $ notification ) {
29+ return ;
30+ }
31+
2932 if ($ notification ->isStillRelevant ()) {
33+ $ notifiable = $ this ->determineNotifiable ();
34+
3035 $ notifiable ->notify ($ notification );
3136 }
3237
@@ -40,7 +45,7 @@ protected function determineNotifiable()
4045 return app ($ notifiableClass );
4146 }
4247
43- protected function determineNotification ($ event ): Notification
48+ protected function determineNotification ($ event )
4449 {
4550 $ eventName = class_basename ($ event );
4651
@@ -55,11 +60,9 @@ protected function determineNotification($event): Notification
5560 return $ notificationName === $ eventName ;
5661 });
5762
58- if (! $ notificationClass ) {
59- throw NotificationCouldNotBeSent:: noNotifcationClassForEvent ($ event );
63+ if ($ notificationClass ) {
64+ return app ( $ notificationClass )-> setEvent ($ event );
6065 }
61-
62- return app ($ notificationClass )->setEvent ($ event );
6366 }
6467
6568 protected function allUptimeMonitorEventClasses (): array
Original file line number Diff line number Diff line change 22
33namespace Spatie \UptimeMonitor \Services \PingMonitors ;
44
5- use Spatie \UptimeMonitor \Models \PingMonitor ;
65use Cache ;
76use Generator ;
87use GuzzleHttp \Client ;
1110use Illuminate \Support \Collection ;
1211use Log ;
1312use Psr \Http \Message \ResponseInterface ;
13+ use Spatie \UptimeMonitor \Models \UptimeMonitor ;
1414
1515class UptimeMonitorCollection extends Collection
1616{
1717 public function check ()
1818 {
1919 $ this ->resetItemKeys ();
2020
21- Log:: info ("Start checking for {$ this ->count ()} monitors... " );
21+ consoleOutput ()-> info ("Start checking for {$ this ->count ()} monitors... " );
2222
2323 (new EachPromise ($ this ->getPromises (), [
2424 'concurrency ' => 100 ,
@@ -71,7 +71,7 @@ protected function resetItemKeys()
7171 $ this ->items = $ this ->values ()->all ();
7272 }
7373
74- public function log ($ message , PingMonitor $ pingMonitor )
74+ public function log ($ message , UptimeMonitor $ pingMonitor )
7575 {
7676 Log::info ("$ message (url: {$ pingMonitor ->url } id: {$ pingMonitor ->id }) " );
7777 }
Original file line number Diff line number Diff line change @@ -45,5 +45,7 @@ public function register()
4545 'command.uptime-monitor:delete ' ,
4646 'command.uptime-monitor:list ' ,
4747 ]);
48+
49+ $ this ->app ->singleton (ConsoleOutput::class);
4850 }
4951}
You can’t perform that action at this time.
0 commit comments