notify-eu / notify-bundle
Symfony 的通知包
v1.0
2020-02-12 15:26 UTC
Requires
- php: >=7.1
- guzzlehttp/guzzle: ^6.3
- symfony/framework-bundle: ^4.0
Requires (Dev)
- phpunit/phpunit: ^6
- symfony/phpunit-bridge: ^4.0
This package is auto-updated.
Last update: 2024-09-13 18:42:16 UTC
README
此包使得使用 Notify 和 Symfony 4 发送通知变得简单
内容
安装
您可以通过 composer 安装此包
$ composer require notify-eu/notify-bundle
设置 Notify 账户
将 Notify 凭证添加到您的 .env
// .env ... NOTIFY_CLIENT_ID= NOTIFY_SECRET= NOTIFY_TRANSPORT= NOTIFY_URL= ], ...
NOTIFY_URL
不是必需的。当您想覆盖 Notify 调用的端点时可以使用。例如,测试/生产环境使用不同的 URL
使用方法
- 在您的服务/控制器中加载 'notifyService'
- 创建一个带所需参数的 NotifyMessage 对象
- 发送消息
<?php namespace App\Controller; use NotifyEu\NotifyBundle\Entity\NotifyMessage; use NotifyEu\NotifyBundle\Service\NotifyService; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class IndexController extends AbstractController { protected $notifyService; public function __construct(NotifyService $notifyService) { $this->notifyService = $notifyService; } /** * @Route("/notify", name="app_notify") * @return Response */ public function index() { $message = (new NotifyMessage()) ->setNotificationType('resetPassword') ->addRecipient('John Doe','John.Doe@notify.eu') ->setLanguage('nl') ->setParams(['username' => 'John Doe']); $response = $this->notifyService->send($message); if ($response['success'] == true) { return new Response('Notification send!'); } } }
NotifyMessage
确保向消息中添加一个收件人
$message->addRecipient('John Doe','John.Doe@notify.eu')
所有可用方法
notificationType('')
:接受一个字符串值。addRecipient($array)
:接受一个 'name'/'recipient' 键的数组transport('')
:接受一个字符串值。如果没有设置,将回退到 .env 文件中的 NOTIFY_TRANSPORTlanguage('')
:接受一个字符串值。params($array)
:接受一个键/值参数的数组Cc($array)
:接受一个 'name'/'recipient' 键的数组Bcc($array)
:接受一个 'name'/'recipient' 键的数组
变更日志
请参阅 变更日志 了解最近的变化。
测试
$ composer test
安全
如果您发现任何与安全相关的问题,请通过电子邮件 info@notify.eu 而不是使用问题跟踪器。
贡献
请参阅 贡献指南 获取详细信息。
致谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。