ArrayRecipientIterator.php 1.2KB

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 interator.
  11. * @package Swift
  12. * @subpackage Mailer
  13. * @author Chris Corbyn
  14. */
  15. class Swift_Mailer_ArrayRecipientIterator implements Swift_Mailer_RecipientIterator
  16. {
  17. /**
  18. * The list of recipients.
  19. * @var array
  20. * @access private
  21. */
  22. private $_recipients = array();
  23. /**
  24. * Create a new ArrayRecipientIterator from $recipients.
  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. * @return boolean
  34. */
  35. public function hasNext()
  36. {
  37. return !empty($this->_recipients);
  38. }
  39. /**
  40. * Returns an array where the keys are the addresses of recipients and the
  41. * values are the names.
  42. * e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL)
  43. * @return array
  44. */
  45. public function nextRecipient()
  46. {
  47. return array_splice($this->_recipients, 0, 1);
  48. }
  49. }