1 | <?php |
||
8 | class WebPushChannel |
||
9 | { |
||
10 | /** @var \Minishlink\WebPush\WebPush */ |
||
11 | protected $webPush; |
||
12 | |||
13 | /** |
||
14 | * @param \Minishlink\WebPush\WebPush $webPush |
||
15 | * @return void |
||
|
|||
16 | */ |
||
17 | 2 | public function __construct(WebPush $webPush) |
|
21 | |||
22 | /** |
||
23 | * Send the given notification. |
||
24 | * |
||
25 | * @param mixed $notifiable |
||
26 | * @param \Illuminate\Notifications\Notification $notification |
||
27 | * @return void |
||
28 | */ |
||
29 | 2 | public function send($notifiable, Notification $notification) |
|
30 | { |
||
31 | 2 | $subscriptions = $notifiable->routeNotificationFor('WebPush'); |
|
32 | |||
33 | 2 | if ($subscriptions->isEmpty()) { |
|
34 | return; |
||
35 | } |
||
36 | |||
37 | 2 | $payload = json_encode($notification->toWebPush($notifiable, $notification)->toArray()); |
|
38 | |||
39 | 2 | $subscriptions->each(function ($sub) use ($payload) { |
|
40 | 2 | $this->webPush->sendNotification( |
|
41 | 2 | $sub->endpoint, |
|
42 | 2 | $payload, |
|
43 | 2 | $sub->public_key, |
|
44 | 2 | $sub->auth_token |
|
45 | ); |
||
46 | 2 | }); |
|
47 | |||
48 | 2 | $response = $this->webPush->flush(); |
|
49 | |||
50 | 2 | $this->deleteInvalidSubscriptions($response, $subscriptions); |
|
51 | 2 | } |
|
52 | |||
53 | /** |
||
54 | * @param array|bool $response |
||
55 | * @param \Illuminate\Database\Eloquent\Collection $subscriptions |
||
56 | * @return void |
||
57 | */ |
||
58 | 2 | protected function deleteInvalidSubscriptions($response, $subscriptions) |
|
70 | } |
||
71 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.