1. Go to this page and download the library: Download andydefer/push-notifier 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/ */
andydefer / push-notifier example snippets
ndydefer\PushNotifier\Core\NotificationFactory;
// 1. Créer une factory
$factory = new NotificationFactory();
// 2. Créer un service Firebase à partir du fichier JSON
$firebaseService = $factory->makeFirebaseServiceFromJsonFile(
__DIR__ . '/storage/firebase-credentials.json'
);
// 3. Envoyer une notification simple
$deviceToken = 'votre_token_appareil_fcm';
$response = $firebaseService->sendInfo(
$deviceToken,
'Bonjour !',
'Ceci est ma première notification push.'
);
if ($response->success) {
echo "Notification envoyée avec succès ! ID : " . $response->messageId;
} else {
echo "Échec de l'envoi : " . $response->errorMessage;
}
$factory = new NotificationFactory();
// Créer un service de différentes manières
$service = $factory->makeFirebaseServiceFromJsonFile($jsonPath);
$service = $factory->makeFirebaseServiceFromJsonString($jsonContent);
$service = $factory->makeFirebaseServiceFromArray($configArray);
$service = $factory->makeFirebaseServiceFromEnv($_ENV);
// Exemple : Utiliser un client HTTP personnalisé
use App\Services\MyCustomHttpClient;
$factory = new NotificationFactory(
new MyCustomHttpClient() // Injecté ici
);
$service = $factory->makeFirebaseServiceFromJsonFile($jsonPath);
use Andydefer\PushNotifier\Dtos\FcmMessageData;
// Notification d'information (title et body uniquement)
$info = FcmMessageData::info('Mise à jour', 'Nouvelle version disponible.');
// Notification silencieuse (avec connected: true par défaut)
$ping = FcmMessageData::ping();