sfRouteCollection.class.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  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. * sfObjectRouteCollection represents a collection of routes.
  11. *
  12. * @package symfony
  13. * @subpackage routing
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfRouteCollection.class.php 11471 2008-09-12 10:03:49Z fabien $
  16. */
  17. class sfRouteCollection implements Iterator
  18. {
  19. protected
  20. $count = 0,
  21. $options = array(),
  22. $routes = array();
  23. /**
  24. * Constructor.
  25. *
  26. * @param array $options An array of options
  27. */
  28. public function __construct(array $options)
  29. {
  30. if (!isset($options['name']))
  31. {
  32. throw new InvalidArgumentException('You must pass a "name" option to sfRouteCollection');
  33. }
  34. $this->options = $options;
  35. }
  36. /**
  37. * Returns the routes.
  38. *
  39. * @return array The routes
  40. */
  41. public function getRoutes()
  42. {
  43. return $this->routes;
  44. }
  45. /**
  46. * Returns the options.
  47. *
  48. * @return array The options
  49. */
  50. public function getOptions()
  51. {
  52. return $this->options;
  53. }
  54. /**
  55. * Reset the error array to the beginning (implements the Iterator interface).
  56. */
  57. public function rewind()
  58. {
  59. reset($this->routes);
  60. $this->count = count($this->routes);
  61. }
  62. /**
  63. * Get the name of the current route (implements the Iterator interface).
  64. *
  65. * @return string The key
  66. */
  67. public function key()
  68. {
  69. return key($this->routes);
  70. }
  71. /**
  72. * Returns the current route (implements the Iterator interface).
  73. *
  74. * @return mixed The escaped value
  75. */
  76. public function current()
  77. {
  78. return current($this->routes);
  79. }
  80. /**
  81. * Moves to the next route (implements the Iterator interface).
  82. */
  83. public function next()
  84. {
  85. next($this->routes);
  86. --$this->count;
  87. }
  88. /**
  89. * Returns true if the current route is valid (implements the Iterator interface).
  90. *
  91. * @return boolean The validity of the current route; true if it is valid
  92. */
  93. public function valid()
  94. {
  95. return $this->count > 0;
  96. }
  97. }