NullTransport.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. * {@inheritdoc}
  48. */
  49. public function ping()
  50. {
  51. return true;
  52. }
  53. /**
  54. * Sends the given message.
  55. *
  56. * @param string[] $failedRecipients An array of failures by-reference
  57. *
  58. * @return int The number of sent emails
  59. */
  60. public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
  61. {
  62. if ($evt = $this->eventDispatcher->createSendEvent($this, $message)) {
  63. $this->eventDispatcher->dispatchEvent($evt, 'beforeSendPerformed');
  64. if ($evt->bubbleCancelled()) {
  65. return 0;
  66. }
  67. }
  68. if ($evt) {
  69. $evt->setResult(Swift_Events_SendEvent::RESULT_SUCCESS);
  70. $this->eventDispatcher->dispatchEvent($evt, 'sendPerformed');
  71. }
  72. $count = (
  73. \count((array) $message->getTo())
  74. + \count((array) $message->getCc())
  75. + \count((array) $message->getBcc())
  76. );
  77. return $count;
  78. }
  79. /**
  80. * Register a plugin.
  81. */
  82. public function registerPlugin(Swift_Events_EventListener $plugin)
  83. {
  84. $this->eventDispatcher->bindEventListener($plugin);
  85. }
  86. }