1<?php
2
3/*
4 * This file is part of SwiftMailer.
5 * (c) 2009 Fabien Potencier <fabien.potencier@gmail.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11/**
12 * Pretends messages have been sent, but just ignores them.
13 *
14 * @author Fabien Potencier
15 */
16class Swift_Transport_NullTransport implements Swift_Transport
17{
18    /** The event dispatcher from the plugin API */
19    private $_eventDispatcher;
20
21    /**
22     * Constructor.
23     */
24    public function __construct(Swift_Events_EventDispatcher $eventDispatcher)
25    {
26        $this->_eventDispatcher = $eventDispatcher;
27    }
28
29    /**
30     * Tests if this Transport mechanism has started.
31     *
32     * @return bool
33     */
34    public function isStarted()
35    {
36        return true;
37    }
38
39    /**
40     * Starts this Transport mechanism.
41     */
42    public function start()
43    {
44    }
45
46    /**
47     * Stops this Transport mechanism.
48     */
49    public function stop()
50    {
51    }
52
53    /**
54     * Sends the given message.
55     *
56     * @param Swift_Mime_Message $message
57     * @param string[]           $failedRecipients An array of failures by-reference
58     *
59     * @return int The number of sent emails
60     */
61    public function send(Swift_Mime_Message $message, &$failedRecipients = null)
62    {
63        if ($evt = $this->_eventDispatcher->createSendEvent($this, $message)) {
64            $this->_eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
65            if ($evt->bubbleCancelled()) {
66                return 0;
67            }
68        }
69
70        if ($evt) {
71            $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
72            $this->_eventDispatcher->dispatchEvent($evt, 'sendPerformed');
73        }
74
75        $count = (
76            count((array) $message->getTo())
77            + count((array) $message->getCc())
78            + count((array) $message->getBcc())
79            );
80
81        return $count;
82    }
83
84    /**
85     * Register a plugin.
86     *
87     * @param Swift_Events_EventListener $plugin
88     */
89    public function registerPlugin(Swift_Events_EventListener $plugin)
90    {
91        $this->_eventDispatcher->bindEventListener($plugin);
92    }
93}
94