ArrayRecipientIterator.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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
  16. implements Swift_Mailer_RecipientIterator
  17. {
  18. /**
  19. * The list of recipients.
  20. * @var array
  21. * @access private
  22. */
  23. private $_recipients = array();
  24. /**
  25. * Create a new ArrayRecipientIterator from $recipients.
  26. * @param array $recipients
  27. */
  28. public function __construct(array $recipients)
  29. {
  30. $this->_recipients = $recipients;
  31. }
  32. /**
  33. * Returns true only if there are more recipients to send to.
  34. * @return boolean
  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.
  43. * e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL)
  44. * @return array
  45. */
  46. public function nextRecipient()
  47. {
  48. return array_splice($this->_recipients, 0, 1);
  49. }
  50. }