1. Go to this page and download the library: Download ez-php/push library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ez-php / push example snippets
use EzPhp\HttpClient\HttpClientServiceProvider;
use EzPhp\Push\PushServiceProvider;
$app->register(HttpClientServiceProvider::class);
$app->register(PushServiceProvider::class);
use EzPhp\Push\Push;
use EzPhp\Push\PushMessage;
Push::send('device-token', new PushMessage(
title: 'Order shipped',
body: 'Your order #42 is on its way.',
data: ['order_id' => '42'],
badge: 1,
sound: 'default',
));
$results = Push::sendToMany(['token-a', 'token-b'], $message);
foreach ($results as $token => $error) {
if ($error !== null) {
// e.g. drop $token from storage if $error indicates it is unregistered
}
}
Push::send($subscriptionJson, new PushMessage('Order shipped', 'On its way', ['order_id' => '42']));
use EzPhp\Push\Driver\ArrayDriver;
use EzPhp\Push\Push;
use EzPhp\Push\Pusher;
$driver = new ArrayDriver();
Push::setPusher(new Pusher($driver));
// ... exercise code under test ...
$messages = $driver->sentTo('device-token');
assert(count($messages) === 1);
Push::resetPusher();
use EzPhp\Push\PushDriverInterface;
use EzPhp\Push\PushMessage;
final class SmsDriver implements PushDriverInterface
{
public function send(string $token, PushMessage $message): void
{
// deliver via your own provider
}
}
$app->bind(PushDriverInterface::class, fn () => new SmsDriver());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.