SymfonySitemapSourceIterator.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /*
  3. * This file is part of the Sonata project.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  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 Exporter\Source;
  11. use Symfony\Component\Routing\RouterInterface;
  12. class SymfonySitemapSourceIterator implements SourceIteratorInterface
  13. {
  14. protected $router;
  15. protected $source;
  16. protected $routeName;
  17. protected $parameters;
  18. /**
  19. * @param SourceIteratorInterface $source
  20. * @param RouterInterface $router
  21. * @param string $routeName
  22. * @param array $parameters
  23. */
  24. public function __construct(SourceIteratorInterface $source, RouterInterface $router, $routeName, array $parameters = array())
  25. {
  26. $this->source = $source;
  27. $this->router = $router;
  28. $this->routeName = $routeName;
  29. $this->parameters = $parameters;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function current()
  35. {
  36. $data = $this->source->current();
  37. $parameters = array_merge($this->parameters, array_intersect_key($data, $this->parameters));
  38. if (!isset($data['url'])) {
  39. $data['url'] = $this->router->generate($this->routeName, $parameters, true);
  40. }
  41. return $data;
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function next()
  47. {
  48. $this->source->next();
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function key()
  54. {
  55. return $this->source->key();
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function valid()
  61. {
  62. return $this->source->valid();
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function rewind()
  68. {
  69. $this->source->rewind();
  70. }
  71. }