ArrayRecipientIterator.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. * @package Swift
  13. * @subpackage Mailer
  14. * @author Chris Corbyn
  15. */
  16. class Swift_Mailer_ArrayRecipientIterator implements Swift_Mailer_RecipientIterator
  17. {
  18. /**
  19. * The list of recipients.
  20. *
  21. * @var array
  22. */
  23. private $_recipients = array();
  24. /**
  25. * Create a new ArrayRecipientIterator from $recipients.
  26. *
  27. * @param array $recipients
  28. */
  29. public function __construct(array $recipients)
  30. {
  31. $this->_recipients = $recipients;
  32. }
  33. /**
  34. * Returns true only if there are more recipients to send to.
  35. *
  36. * @return boolean
  37. */
  38. public function hasNext()
  39. {
  40. return !empty($this->_recipients);
  41. }
  42. /**
  43. * Returns an array where the keys are the addresses of recipients and the
  44. * values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL)
  45. *
  46. * @return array
  47. */
  48. public function nextRecipient()
  49. {
  50. return array_splice($this->_recipients, 0, 1);
  51. }
  52. }