1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Laravel Desktop Notifier. |
5
|
|
|
* |
6
|
|
|
* (c) Nuno Maduro <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace NunoMaduro\LaravelDesktopNotifier; |
13
|
|
|
|
14
|
|
|
use Illuminate\Console\Command; |
15
|
|
|
use Joli\JoliNotif\NotifierFactory; |
16
|
|
|
use Illuminate\Support\ServiceProvider; |
17
|
|
|
use Joli\JoliNotif\NotifierFactory; |
|
|
|
|
18
|
|
|
use NunoMaduro\LaravelDesktopNotifier\Contracts\Notification as NotificationContract; |
19
|
|
|
use NunoMaduro\LaravelDesktopNotifier\Contracts\Notifier as NotifierContract; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The is the Laravel Desktop Notifier service provider class. |
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
|
|
|
|
77
|
|
|
$this->app->alias('desktop.notification', NotificationContract::class); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|