Skip to content

Releases: web-push-libs/web-push-php

v5.1.0

29 Nov 08:45
Compare
Choose a tag to compare
  • Allow client subscription structure to be directly passed to create (thx @maglnet!)

v5.0.0

27 Nov 18:58
Compare
Choose a tag to compare

Breaking changes

You now need to iterate over the results of flush in order to actually send the notifications.

The way you handle the results of the flush() method should be changed. In v5 the flush always returns a Generator object. This means that you can still iterate over it, but you wouldn't be able to store it, at least not as-is. Using the example from the docs, the responses would now look different:

PLEASE NOTE:
\Generator is returned even if you only send one message.

BEFORE:

$res = [
    [ // first notification (failed)
        'success' => false,
        'endpoint' => $theEndpointToDeleteInYourDatabaseIfExpired,
        'message' => $responseMessage,
        'statusCode' => $responseStatusCode,
        'headers' => $responseHeaders,
        'content' => $responseContent, // you may have more infos here
        'expired' => $isTheEndpointWrongOrExpired,
    ],
    [ // second notification (succeeded)
        'success' => true,
    ],
    [ // third notification
        ...
    ], ...
];

AFTER:

var_dump($res); // \Generator

/** \Minishlink\WebPush\MessageSentReport */
foreach ($res as $result) {
    // you now have access to request & response objects

    /** @var \Psr\Http\Message\RequestInterface $request */
    $request = $result-> getRequest();
    /** @var \Psr\Http\Message\ResponseInterface $response */
    $response = $result->getResponse();

    if ($result->isSuccess()) {
        // process successful message sent
        $logger->log('Notification with payload %s successfully sent for endpoint %s.' [
            json_decode((string) $response->getBody()),
            $result->getEndpoint()
        ]);
    } else {
        // or a failed one - check expiration first
        if ($result->isSubscriptionExpired()) {
            // this is just an example code, not included in library!
            $db->markExpired($result->getEndpoint());
        } else {
            // process faulty message
            $logger->log('Notification failed: %s. Payload: %s, endpoint: %s' [
                $result->getReason(),
                json_decode((string) $response->getBody()),
                $result->getEndpoint()
            ]);
        }
    }
}

v4.0.2

13 May 15:00
5c2d2a5
Compare
Choose a tag to compare
  • Fix Subscription::create when not giving every keys

v4.0.1

12 Apr 12:22
Compare
Choose a tag to compare

v4.0.0

17 Mar 20:47
75d198b
Compare
Choose a tag to compare

See migration commit in web-push-php-example

  • Support new aes128gcm content encoding (used notably in MS Edge)

You get your content encoding in your client JS code, and store it in your database alongside the rest of the subscription:

const contentEncoding = (PushManager.supportedContentEncodings || ['aesgcm'])[0];
  • [BREAKING] You must use a new Subscription object in sendNotification

Before:

use Minishlink\WebPush\WebPush;

$webPush->sendNotification(
    'endpoint',
    'payload', // optional (defaults null)
    'userPublicKey', // optional (defaults null)
    'userAuthToken' // optional (defaults null)
);

After:

use Minishlink\WebPush\WebPush;
use Minishlink\WebPush\Subscription;

$subcription = Subscription::create([
    'endpoint' => 'endpoint',
    'publicKey' => 'public key', // optional
    'authToken' => 'authToken', // optional
    'contentEncoding' => 'aesgcm', // optional, one of PushManager.supportedContentEncodings
]);

$webPush->sendNotification(
    $notification['subscription'],
    $notification['payload'] // optional (defaults null)
);

v3.0.2

17 Mar 10:50
18ddf3a
Compare
Choose a tag to compare
  • Optimized encryption keys generation (thanks @Spomky!)

v3.0.1

16 Mar 19:10
Compare
Choose a tag to compare
  • Fixed random rare case where the encryption failed

v3.0.0

16 Mar 12:50
c09b8e2
Compare
Choose a tag to compare
  • [BREAKING] PHP 7.1+ is now necessary
  • Another encryption library (web-token) is being used. It leverages the new encryption library in PHP7.2 for a performance boost. Thanks @Spomky!

v2.0.1

22 Nov 20:05
Compare
Choose a tag to compare
  • The tests folder is ignored when installed with composer and --prefer-dist (thx @staabm!)

v2.0.0

12 Oct 20:33
Compare
Choose a tag to compare
  • Removed compatibility for PHP < 7
  • Updated dependencies