@@ -45,21 +45,30 @@ class ScheduleListCommand extends Command
45
45
public function handle (Schedule $ schedule )
46
46
{
47
47
$ events = collect ($ schedule ->events ());
48
- $ terminalWidth = $ this ->getTerminalWidth ();
48
+
49
+ if ($ events ->isEmpty ()) {
50
+ $ this ->comment ('No scheduled tasks have been defined. ' );
51
+
52
+ return ;
53
+ }
54
+
55
+ $ terminalWidth = self ::getTerminalWidth ();
56
+
49
57
$ expressionSpacing = $ this ->getCronExpressionSpacing ($ events );
50
58
51
- $ events = $ events ->map (function ($ event ) use ($ terminalWidth , $ expressionSpacing ) {
59
+ $ timezone = new DateTimeZone ($ this ->option ('timezone ' ) ?? config ('app.timezone ' ));
60
+
61
+ $ events = $ events ->map (function ($ event ) use ($ terminalWidth , $ expressionSpacing , $ timezone ) {
52
62
$ expression = $ this ->formatCronExpression ($ event ->expression , $ expressionSpacing );
53
63
54
64
$ command = $ event ->command ;
55
65
$ description = $ event ->description ;
56
66
57
67
if (! $ this ->output ->isVerbose ()) {
58
- $ command = str_replace (
59
- Application:: artisanBinary () ,
68
+ $ command = str_replace ([Application:: phpBinary (), Application:: artisanBinary ()], [
69
+ ' php ' ,
60
70
preg_replace ("#[' \"]# " , '' , Application::artisanBinary ()),
61
- str_replace (Application::phpBinary (), 'php ' , $ event ->command )
62
- );
71
+ ], $ event ->command );
63
72
}
64
73
65
74
if ($ event instanceof CallbackEvent) {
@@ -77,7 +86,7 @@ public function handle(Schedule $schedule)
77
86
78
87
$ nextDueDate = Carbon::create ((new CronExpression ($ event ->expression ))
79
88
->getNextRunDate (Carbon::now ()->setTimezone ($ event ->timezone ))
80
- ->setTimezone (new DateTimeZone ( $ this -> option ( ' timezone ' ) ?? config ( ' app.timezone ' )) )
89
+ ->setTimezone ($ timezone )
81
90
);
82
91
83
92
$ nextDueDate = $ this ->output ->isVerbose ()
@@ -109,11 +118,7 @@ public function handle(Schedule $schedule)
109
118
) : '' ];
110
119
});
111
120
112
- if ($ events ->isEmpty ()) {
113
- return $ this ->comment ('No scheduled tasks have been defined. ' );
114
- }
115
-
116
- $ this ->output ->writeln (
121
+ $ this ->line (
117
122
$ events ->flatten ()->filter ()->prepend ('' )->push ('' )->toArray ()
118
123
);
119
124
}
@@ -140,10 +145,10 @@ private function getCronExpressionSpacing($events)
140
145
*/
141
146
private function formatCronExpression ($ expression , $ spacing )
142
147
{
143
- $ expression = explode (' ' , $ expression );
148
+ $ expressions = explode (' ' , $ expression );
144
149
145
150
return collect ($ spacing )
146
- ->map (fn ($ length , $ index ) => $ expression [ $ index ] = str_pad ($ expression [$ index ], $ length ))
151
+ ->map (fn ($ length , $ index ) => str_pad ($ expressions [$ index ], $ length ))
147
152
->implode (' ' );
148
153
}
149
154
0 commit comments