TraversableString.php 878B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 OpenSky Project Inc
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Assetic\Util;
  11. /**
  12. * An object that can be used as either a string or array.
  13. *
  14. * @author Kris Wallsmith <kris.wallsmith@gmail.com>
  15. */
  16. class TraversableString implements \IteratorAggregate, \Countable
  17. {
  18. private $one;
  19. private $many;
  20. public function __construct($one, array $many)
  21. {
  22. $this->one = $one;
  23. $this->many = $many;
  24. }
  25. public function getIterator()
  26. {
  27. return new \ArrayIterator($this->many);
  28. }
  29. public function count()
  30. {
  31. return count($this->many);
  32. }
  33. public function __toString()
  34. {
  35. return (string) $this->one;
  36. }
  37. }