You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -208,8 +207,9 @@ it as a parameter : `$webPush->flush($batchSize)`.
208
207
209
208
### Server errors
210
209
You can see what the browser vendor's server sends back in case it encountered an error (push subscription expiration, wrong parameters...).
211
-
`sendNotification()` (with `$flush` as `true`) and `flush()`**always** returns a [`\Generator`](http://php.net/manual/en/language.generators.php) with [`MessageSentReport`](https://github.com/web-push-libs/web-push-php/blob/master/src/MessageSentReport.php) objects, even if you just send one notification.
212
-
To loop through the results, just pass it into `foreach`. You can also use [`iterator_to_array`](http://php.net/manual/en/function.iterator-to-array.php) to check the contents while debugging.
210
+
211
+
*`sendOneNotification()` returns a [`MessageSentReport`](https://github.com/web-push-libs/web-push-php/blob/master/src/MessageSentReport.php)
212
+
*`flush()` returns a [`\Generator`](http://php.net/manual/en/language.generators.php) with [`MessageSentReport`](https://github.com/web-push-libs/web-push-php/blob/master/src/MessageSentReport.php) objects. To loop through the results, just pass it into `foreach`. You can also use [`iterator_to_array`](http://php.net/manual/en/function.iterator-to-array.php) to check the contents while debugging.
You won't be able to send any payload, so you'll only be able to use `sendNotification($subscription)`.
349
+
You won't be able to send any payload, so you'll only be able to use `sendOneNotification($subscription)` or `queueNotification($subscription)`.
350
350
Install the library with `composer` using `--ignore-platform-reqs`.
351
351
The workaround for getting the payload is to fetch it in the service worker ([example](https://github.com/Minishlink/physbook/blob/2ed8b9a8a217446c9747e9191a50d6312651125d/web/service-worker.js#L75)).
Copy file name to clipboardExpand all lines: src/WebPush.php
+16-8Lines changed: 16 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -102,20 +102,16 @@ public function __construct(array $auth = [], array $defaultOptions = [], ?int $
102
102
}
103
103
104
104
/**
105
-
* Send a notification.
105
+
* Queue a notification. Will be sent when flush() is called.
106
106
*
107
107
* @param SubscriptionInterface $subscription
108
-
* @param string|null $payload If you want to send an array, json_encode it
109
-
* @param bool $flush If you want to flush directly (usually when you send only one notification)
108
+
* @param string|null $payload If you want to send an array or object, json_encode it
110
109
* @param array $options Array with several options tied to this notification. If not set, will use the default options that you can set in the WebPush object
111
110
* @param array $auth Use this auth details instead of what you provided when creating WebPush
112
111
*
113
-
* @return \Generator|MessageSentReport[]|true Return an array of information if $flush is set to true and the queued requests has failed.
* @param string|null $payload If you want to send an array or object, json_encode it
139
+
* @param array $options Array with several options tied to this notification. If not set, will use the default options that you can set in the WebPush object
140
+
* @param array $auth Use this auth details instead of what you provided when creating WebPush
0 commit comments