1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelZero\Framework\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Scheduling\Schedule; |
6
|
|
|
use Illuminate\Contracts\Container\Container; |
7
|
|
|
use Illuminate\Console\Command as BaseCommand; |
8
|
|
|
use NunoMaduro\LaravelDesktopNotifier\Contracts\Notifier; |
9
|
|
|
use NunoMaduro\LaravelDesktopNotifier\Contracts\Notification; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* This is the Laravel Zero Framework abstract command class. |
13
|
|
|
* |
14
|
|
|
* @author Nuno Maduro <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
abstract class Command extends BaseCommand |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Execute the console command. Here goes the command |
20
|
|
|
* code. |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
abstract public function handle(): void; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Returns the application container. |
28
|
|
|
* |
29
|
|
|
* @return \Illuminate\Contracts\Container\Container |
30
|
|
|
*/ |
31
|
|
|
public function getContainer(): Container |
32
|
|
|
{ |
33
|
|
|
return $this->getLaravel(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Define the command's schedule. |
38
|
|
|
* |
39
|
|
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function schedule(Schedule $schedule): void |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Gets the concrete implementation of the notifier. Then |
49
|
|
|
* creates a new notification and send it through the notifier. |
50
|
|
|
* |
51
|
|
|
* @param string $title |
52
|
|
|
* @param string $body |
53
|
|
|
* @param string|null $icon |
54
|
|
|
*/ |
55
|
|
|
public function notify(string $title, string $body, $icon = null): void |
56
|
|
|
{ |
57
|
|
|
$notifier = $this->getContainer() |
58
|
|
|
->make(Notifier::class); |
59
|
|
|
|
60
|
|
|
$notification = $this->getContainer() |
61
|
|
|
->make(Notification::class) |
62
|
|
|
->setTitle($title) |
63
|
|
|
->setBody($body) |
64
|
|
|
->setIcon($icon); |
65
|
|
|
|
66
|
|
|
$notifier->send($notification); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Performs the given task and outputs |
71
|
|
|
* the result. |
72
|
|
|
* |
73
|
|
|
* @param string $title |
74
|
|
|
* @param callable $task |
75
|
|
|
* |
76
|
|
|
* @return $this |
77
|
|
|
*/ |
78
|
|
|
public function task(string $title, callable $task) |
79
|
|
|
{ |
80
|
|
|
$this->output->writeln( |
81
|
|
|
"$title: ".($task() ? '<info>✔</info>' : '<error>failed</error>') |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.