NullTransport.php 2.2 KB

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