drewlabs/envoyer
Composer 安装命令:
composer require drewlabs/envoyer
包简介
Envoyer client library
关键字:
README 文档
README
Client library for sending text message, email, etc... notification using various adapters / drivers.
Usage
The library requires drivers for supported providers like [ Amazon AWS SES ], [ TWILIO Sendgrid ] driver (for sending mail using [ Twilio Sendgrid PHP API ]), [SMTP] driver (for sending mails using an SMTP connection), [ Twilio Message API ] (For sending Text message using Twilio), and SMPP driver (for sending message using an SMPP connection to an SMPP server), etc.
-- Sending an mail
For simple mail (mail without attachment), there is no need to implements [Drewlabs\Contracts\Notification\AttachmentsNotification] as it is only required for mails with attachments.
// Create a notification class // Mail.php use Drewlabs\Envoyer\Contracts\AttachmentsAware; use Drewlabs\Envoyer\Contracts\NotificationInterface; use SplFileInfo; /** @package Drewlabs\Notifications\Tests\Stubs */ class Mail implements NotificationInterface, AttachmentsAware { public function setAttachments($attachments = []) { } public function getAttachments() { return [ new SplFileInfo(__DIR__ . '/../contents/bordereau.pdf'), ]; } public function getCc() { return null; } public function getSubject() { return "Successful registration"; } public function getSender() { return new Address; } public function getReceiver() { return "azandrewdevelopper@gmail.com"; } public function getContent() { return "<p>Hey Azandrew! Thank you for your registration</p>"; } } // defines a test driver to use DriverRegistryFacade::defineDriver('test', static function () { return new TestDriver(); }); // Send notification using command interface $result = $command->driver('test')->send(new Mail);
- SMTP
-- Integration
composer require drewlabs/envoyer-smtp
-- Sending mail
// SendMail.php $result = $command->driver('smtp')->send(new Mail);
- Twilio Message API
-- Installation
composer require drewlabs/envoyer-twilio
-- Sending Text Message
// SendMessage.php $result = $command->driver('smtp')->send(new Message);
- SMPP Server
-- Installation
composer require drewlabs/envoyer-smpp
-- Sending Text messages
// SendMessage.php $result = $command->driver('smpp')->send(new Message);
- Custom Driver
Custom / Thrird party drivers implementations must implements [Drewlabs\Envoyer\Contracts\ClientInterface] and define the custom logic to send notification.
use Drewlabs\Envoyer\Contracts\ClientInterface; use Drewlabs\Envoyer\Contracts\NotificationInterface; use Drewlabs\Envoyer\Contracts\NotificationResult; use RuntimeException; class TestDriver implements ClientInterface { public function __construct() { } public function sendRequest(NotificationInterface $instance): NotificationResult { // TODO : Provide send request implementation logic } }
API
- Mail builder
The mail builder class is a fluent interface for building mail notifications.
Example:
// Start building the mail $mail = \Drewlabs\Envoyer\Mail::new() ->from('...', '...') ->to('...') ->bCc('...') ->subject('...') ->attach(new SplFileInfo(__DIR__ . '/...')) ->content(require __DIR__ . '/...'); // TODO: Send the mail messge using the required driver API
- Text Messages builder
The text message builder is a fluent interface for building text messages to be send as notification instance.
// Create a messageable class $message = Messageable::new() ->from('...') ->to('...') ->content("..."); // Use required driver to send the notification message
- Driver Enum
To avoid typo error for driver names, implementation comes with PHP constant that can be use when contructing command:
use Drewlabs\Notifications\Command; use Drewlabs\Notifications\Drivers; $result = Command::driver(Drivers::AWS_SES)->send(/* ... */);
- The Drivers registry
The drivers registry is a singleton class that allow application developper to register and create notification drivers.
use Drewlabs\Envoyer\DriverRegistryFacade; DriverRegistryFacade::defineDriver('test', static function () { return new TestProvider(); });
Note The factory function/closure passed as parameter to defineDriver must return an instance of Drewlabs\Envoyer\Contracts\ClientInterface else the driver resolver will throw an exception.
drewlabs/envoyer 适用场景与选型建议
drewlabs/envoyer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 131 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mail」 「sms」 「notification」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 drewlabs/envoyer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 drewlabs/envoyer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 drewlabs/envoyer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package makes it easy to send notifications via AfricasTalking with Laravel
Apple Push Notification & Feedback Provider
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
Throttle notifications on a per-channel basis
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Mail libraries used by Zimbra Api
统计信息
- 总下载量: 131
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-11