notiflow-io/notiflow-php
Composer 安装命令:
composer require notiflow-io/notiflow-php
包简介
Official PHP SDK for Notiflow - Event-driven notification platform
README 文档
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
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-07