ArrayRecipientIterator.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 = [];
  22. /**
  23. * Create a new ArrayRecipientIterator from $recipients.
  24. */
  25. public function __construct(array $recipients)
  26. {
  27. $this->recipients = $recipients;
  28. }
  29. /**
  30. * Returns true only if there are more recipients to send to.
  31. *
  32. * @return bool
  33. */
  34. public function hasNext()
  35. {
  36. return !empty($this->recipients);
  37. }
  38. /**
  39. * Returns an array where the keys are the addresses of recipients and the
  40. * values are the names. e.g. ('foo@bar' => 'Foo') or ('foo@bar' => NULL).
  41. *
  42. * @return array
  43. */
  44. public function nextRecipient()
  45. {
  46. return array_splice($this->recipients, 0, 1);
  47. }
  48. }