ArrayRecipientIterator.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of SwiftMailer.
  4. * (c) 2004-2009 Chris Corbyn
  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. * Wraps a standard PHP array in an iterator.
  11. *
  12. * @author Chris Corbyn
  13. */
  14. class Swift_Mailer_ArrayRecipientIterator implements Swift_Mailer_RecipientIterator
  15. {
  16. /**
  17. * The list of recipients.
  18. *
  19. * @var array
  20. */
  21. private $_recipients = array();
  22. /**
  23. * Create a new ArrayRecipientIterator from $recipients.
  24. *
  25. * @param array $recipients
  26. */
  27. public function __construct(array $recipients)
  28. {
  29. $this->_recipients = $recipients;
  30. }
  31. /**
  32. * Returns true only if there are more recipients to send to.
  33. *
  34. * @return bool
  35. */
  36. public function hasNext()
  37. {
  38. return !empty($this->_recipients);
  39. }
  40. /**
  41. * Returns an array where the keys are the addresses of recipients and the
  42. * values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL)
  43. *
  44. * @return array
  45. */
  46. public function nextRecipient()
  47. {
  48. return array_splice($this->_recipients, 0, 1);
  49. }
  50. }