These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 NunoMaduro\LaravelDesktopNotifier\Contracts\Notification as NotificationContract; |
||
18 | use NunoMaduro\LaravelDesktopNotifier\Contracts\Notifier as NotifierContract; |
||
19 | |||
20 | /** |
||
21 | * The is the Laravel Desktop Notifier service provider class. |
||
22 | */ |
||
23 | class LaravelDesktopNotifierServiceProvider extends ServiceProvider |
||
24 | { |
||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | public function boot() |
||
29 | { |
||
30 | /* |
||
31 | * Sends a desktop notification. |
||
32 | * |
||
33 | * @param string $title |
||
34 | * @param string $body |
||
35 | * @param string|null $icon |
||
36 | * |
||
37 | * @return void |
||
38 | */ |
||
39 | Command::macro('notify', function (string $text, string $body, $icon = null) { |
||
40 | $notifier = $this->laravel[Contracts\Notifier::class]; |
||
0 ignored issues
–
show
|
|||
41 | |||
42 | $notification = $this->laravel[Contracts\Notification::class] |
||
43 | ->setTitle($text) |
||
44 | ->setBody($body); |
||
45 | |||
46 | if (! empty($icon)) { |
||
47 | $notification->setIcon($icon); |
||
48 | } |
||
49 | |||
50 | $notifier->send($notification); |
||
51 | }); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | public function register() |
||
58 | { |
||
59 | $this->app->singleton('desktop.notifier', function ($app) { |
||
60 | $config = $app['config']['app.notifiers']; |
||
61 | |||
62 | $notifier = NotifierFactory::create(is_array($config) ? $config : []); |
||
63 | |||
64 | return new Notifier($notifier); |
||
65 | }); |
||
66 | |||
67 | $this->app->alias('desktop.notifier', NotifierContract::class); |
||
68 | |||
69 | $this->app->bind('desktop.notification', function () { |
||
70 | return new Notification(); |
||
71 | }); |
||
72 | |||
73 | $this->app->alias('desktop.notification', NotificationContract::class); |
||
74 | } |
||
75 | } |
||
76 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: