1 | <?php |
||
23 | */ |
||
24 | class LaravelDesktopNotifierServiceProvider extends ServiceProvider |
||
25 | { |
||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | public function boot() |
||
30 | { |
||
31 | /* |
||
32 | * Sends a desktop notification. |
||
33 | * |
||
34 | * @param string $title |
||
35 | * @param string $body |
||
36 | * @param string|null $icon |
||
37 | * |
||
38 | * @return void |
||
39 | */ |
||
40 | Command::macro( |
||
41 | 'notify', |
||
42 | function (string $text, string $body, $icon = null) { |
||
43 | $notifier = $this->app[Contracts\Notifier::class]; |
||
44 | |||
45 | $notification = $this->app[Contracts\Notification::class] |
||
46 | ->setTitle($text) |
||
47 | ->setBody($body); |
||
48 | |||
49 | if (! empty($icon)) { |
||
50 | $notification->setIcon($icon); |
||
51 | } |
||
52 | |||
53 | $notifier->send($notification); |
||
54 | } |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function register() |
||
62 | { |
||
63 | $this->app->singleton('desktop.notifier', function ($app) { |
||
64 | $config = $app['config']['app.notifiers']; |
||
65 | |||
66 | $notifier = NotifierFactory::create(is_array($config) ? $config : []); |
||
67 | |||
68 | return new Notifier($notifier); |
||
69 | }); |
||
70 | |||
71 | $this->app->alias('desktop.notifier', NotifierContract::class); |
||
72 | |||
73 | $this->app->bind('desktop.notification', function () { |
||
74 | return new Notification(); |
||
75 | }); |
||
76 | |||
80 |