php-solution / notification-bundle
用于在Symfony应用程序中使用带有用户通知功能的通知组件的Symfony包
v0.1.1
2017-03-30 09:31 UTC
Requires
- php: >=7.1
- php-solution/notification: ~0.1
- symfony/config: >=3.1
- symfony/dependency-injection: >=3.1
- symfony/event-dispatcher: >=3.1
- symfony/http-kernel: >=3.1
- symfony/options-resolver: >=3.1
Requires (Dev)
- symfony/swiftmailer-bundle: >=2.0
Suggests
- symfony/swiftmailer-bundle: for use SwiftMailer as Notifier
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: ~
安装
- 将其添加到您的composer.json中
"require": {
...
"php-solution/notification-bundle": "dev-master",
...
}
- 运行
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'])
);