notiflow-io / notiflow-php
Official PHP SDK for Notiflow - Event-driven notification platform
dev-main
2026-01-05 13:27 UTC
Requires
- php: ^8.1
Requires (Dev)
- phpunit/phpunit: ^10.0
This package is not auto-updated.
Last update: 2026-04-02 09:14:56 UTC
README
Official PHP SDK for Notiflow - Event-driven notification platform.
Installation
composer require notiflow/notiflow-php
Quick Start
use Notiflow\Notiflow; $notiflow = new Notiflow('sk_live_...'); // Trigger an event $result = $notiflow->trigger('order.completed', [ 'user_id' => 'user_123', 'email' => 'john@example.com', 'order_id' => 'ORD-456', 'total' => 99.99, 'currency' => 'USD', ]); if ($result->isSuccess()) { echo "Event sent! ID: " . $result->eventId; } else { echo "Failed: " . $result->error; }
Features
- Error-safe: Never throws exceptions - all errors are captured in the Result object
- Zero dependencies: Uses native cURL
- PHP 8.1+: Modern PHP with readonly classes and named arguments
- Type-safe: Full type hints and PHPDoc annotations
Usage
Basic Event
$notiflow->trigger('user.signup', ['plan' => 'pro']);
Event with User ID
$notiflow->trigger('subscription.renewed', [ 'plan' => 'enterprise', 'amount' => 199.00, ], 'user_789');
Fire-and-Forget (Async)
When you don't need the response:
$notiflow->triggerAsync('page.viewed', ['url' => '/pricing']);
Alternative Method Names
// These are equivalent: $notiflow->trigger('order.paid', $data); $notiflow->event('order.paid', $data); $notiflow->track('order.paid', $data);
Error Handling
The SDK never throws exceptions. Check the result:
$result = $notiflow->trigger('order.paid', $data); if ($result->isFailure()) { // Log the error, but your app continues running error_log("Notiflow error: " . $result->error); }
Configuration
Custom Base URL
For self-hosted or staging environments:
$notiflow = new Notiflow( apiKey: 'sk_live_...', baseUrl: 'https://your-instance.notiflow.io', );
Custom HTTP Client
Implement HttpClient interface for custom transport:
use Notiflow\Http\HttpClient; class GuzzleHttpClient implements HttpClient { public function post(string $url, array $headers, array $body, int $timeout): HttpResponse { // Your implementation } } $notiflow = new Notiflow( apiKey: 'sk_live_...', httpClient: new GuzzleHttpClient(), );
Laravel Integration
// config/services.php 'notiflow' => [ 'api_key' => env('NOTIFLOW_API_KEY'), 'base_url' => env('NOTIFLOW_URL', 'https://api.notiflow.io'), ], // AppServiceProvider.php $this->app->singleton(Notiflow::class, fn () => new Notiflow( apiKey: config('services.notiflow.api_key'), baseUrl: config('services.notiflow.base_url'), )); // Usage app(Notiflow::class)->trigger('order.shipped', $orderData);
License
MIT