php-solution/notification-bundle

用于在Symfony应用程序中使用带有用户通知功能的通知组件的Symfony包

安装次数: 1,049

依赖者: 0

建议者: 0

安全性: 0

星标: 1

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

v0.1.1 2017-03-30 09:31 UTC

This package is auto-updated.

Last update: 2024-09-14 17:59:04 UTC


README

此包将通知组件集成到Symfony应用程序中。

在开始开发之前,请参阅通知组件的文档

配置

notification:
    extensions:
        use_for_manager: "notification.extension.context_configurator"
        context_configurator:
            enabled: true
        event_dispatcher:
            enabled: false
    notifier_swiftmailer:
        enabled: true
        default_sender: ~

安装

  1. 将其添加到您的composer.json中
    "require": {
        ...
        "php-solution/notification-bundle": "dev-master",
        ...
    }
  1. 运行
    composer update php-solution/notification-bundle

示例

通知类型

    <?php
    namespace AppBundle\Notification;
    
    use PhpSolution\Notification\Context;
    use PhpSolution\Notification\Extension\ContextConfigure\ConfiguratorInterface;
    use PhpSolution\Notification\Rule\RuleInterface;
    use PhpSolution\Notification\Type\AbstractType;
    use PhpSolution\NotificationBundle\Notifier\SwiftMailer\Rule;
    use Symfony\Component\OptionsResolver\OptionsResolver;
    
    class NotificationType extends AbstractType implements ConfiguratorInterface
    {
        /**
         * Must yield RuleInterface
         *
         * @param Context|null $context
         *
         * @return \Generator|RuleInterface|RuleInterface[]
         */
        public function initialize(?Context $context): \Generator
        {
            yield new Rule($context['recipient_email']);
        }
    
        /**
         * @param OptionsResolver $resolver
         */
        public function configureContext(OptionsResolver $resolver)
        {
            $resolver
                ->setRequired('recipient_email')
                ->setAllowedTypes('recipient_email', 'string');
        }
    }        

在控制器上

    $this->get('notification.manager')->notifyType(
        new NotificationType(), 
        new Context(['recipient_email' => 'email@gmail.com'])
    );