notify-eu/notify-bundle

Symfony 的通知包

安装: 2

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 4

分支: 0

开放问题: 0

类型:symfony-bundle

v1.0 2020-02-12 15:26 UTC

This package is auto-updated.

Last update: 2024-09-13 18:42:16 UTC


README

Latest Version on Packagist Software License Build Status StyleCI Total Downloads

此包使得使用 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

使用方法

  1. 在您的服务/控制器中加载 'notifyService'
  2. 创建一个带所需参数的 NotifyMessage 对象
  3. 发送消息
<?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_TRANSPORT
  • language(''):接受一个字符串值。
  • params($array):接受一个键/值参数的数组
  • Cc($array):接受一个 'name'/'recipient' 键的数组
  • Bcc($array):接受一个 'name'/'recipient' 键的数组

变更日志

请参阅 变更日志 了解最近的变化。

测试

$ composer test

安全

如果您发现任何与安全相关的问题,请通过电子邮件 info@notify.eu 而不是使用问题跟踪器。

贡献

请参阅 贡献指南 获取详细信息。

致谢

许可

MIT 许可证 (MIT)。请参阅 许可文件 了解更多信息。