stof/stampie-extra

此软件包已被废弃,不再维护。作者建议使用stampie/extra软件包。

基于事件的stampie/stampie插件

v1.2.0 2021-09-08 13:39 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:21:03 UTC


README

CI

StampieExtra为Stampie提供基于事件的扩展点。它使用Symfony EventDispatcher组件。

用法

Stampie Extra邮件发送器封装了你的Stampie邮件发送器,在发送过程中提供扩展点。

<?php

// include the Composer autoloading
require 'vendor/autoload.php';

$httpClient = new Http\Adapter\Guzzle6\Client();
$innerMailer = new Stampie\Mailer\SendGrid($httpClient, 'username:password');

$dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher();
$mailer = new Stampie\Extra\Mailer($innerMailer, $dispatcher);

$message = // Create your Stampie message

$mailer->send($message);

邮件发送器在发送消息之前将触发stampie.pre_send事件,允许你进行一些更改。

内置监听器

ImpersonateListener

ImpersonateListener允许你在开发过程中替换邮件的收件人,将所有消息发送到单个电子邮件地址。它将在包含原始收件人的X-Stampie-To标题中添加内容。

<?php
$dispatcher->addEventSubscriber(new Stampie\Extra\EventListener\ImpersonateListener('stampie@example.com'));

LoggerListener

LoggerListener允许你记录发送的电子邮件。它期望一个实现了PSR-3 LoggerInterface的日志记录器。

<?php
// create a listener and configure it
$logger = new Monolog\Logger('stampie');
// ...

$dispatcher->addEventSubscriber(new Stampie\Extra\EventListener\LoggerListener($logger));

SpoolMailer

Stampie Extra还提供了一个SpoolMailer,用于在内存中存储消息,并在清空队列时发送它们。

<?php

$mailer = // Create your mailer...
$spoolMailer = new Stampie\Extra\SpoolMailer($mailer);

$message = // Create your Stampie message...
$spoolMailer->send($message);

// Do some logic, for instance flushing the response to the user

// Flush the queue, sending the message with the inner mailer
$spoolMailer->flushSpool();

测试

Stampie Extra使用持续集成Travis进行测试,并旨在达到高覆盖率。