Extensions for the Stampie library
PHP
Switch branches/tags
Latest commit 5838838 Jun 8, 2017 @stof Update the changelog
Permalink
Failed to load latest commit information.
src/Stampie/Extra Switch the LoggerListener to use PSR-3 Feb 20, 2017
tests/Stampie/Extra/Tests
.gitignore Added the readme and the testsuite setup Jul 13, 2012
.travis.yml
CHANGELOG.md Update the changelog Jun 8, 2017
LICENSE
README.md
composer.json Use autoload-dev for test autoloading Feb 20, 2017
phpunit.xml.dist Use autoload-dev for test autoloading Feb 20, 2017

README.md

Stampie

Build Status

StampieExtra provides an event-based extension point for Stampie. It uses the Symfony2 EventDispatcher component.

Usage

The StampieExtra mailer wraps your Stampie mailer to provides extension points in the sendign process.

<?php

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

$adapter = new Stampie\Adapter\Buzz(new Buzz\Browser());
$innerMailer = new Stampie\Mailer\SendGrid($adapter, 'username:password');

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

$message = // Create your Stampie message

$mailer->send($message);

The mailer will then dispatch the stampie.pre_send event before sending the message, allowing you to apply some changes.

Built-in listeners

ImpersonateListener

The ImpersonateListener allows you to replace the recipient of the mail during development to send all messages to a single email address. It will add a X-Stampie-To header containing the original recipient.

<?php
$dispatcher->addEventSubscriber(new Stampie\Extra\EventListener\ImpersonateListener('stof@notk.org'));

LoggerListener

The LoggerListener allows you to log sent emails. It expects a logger implementing the Symfony2 LoggerInterface.

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

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

SpoolMailer

StampieExtra also provides a SpoolMailer storing the messages in memory and sending them when flushing the queue.

<?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->flushQueue();

Testing

StampieExtra is Continuous Integration tested with Travis and aims for a high coverage percentage.