RouterHelper.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
  3. use Symfony\Component\Templating\Helper\Helper;
  4. use Symfony\Component\Routing\Router;
  5. /*
  6. * This file is part of the Symfony framework.
  7. *
  8. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  9. *
  10. * This source file is subject to the MIT license that is bundled
  11. * with this source code in the file LICENSE.
  12. */
  13. /**
  14. * RouterHelper manages links between pages in a template context.
  15. *
  16. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  17. */
  18. class RouterHelper extends Helper
  19. {
  20. protected $generator;
  21. /**
  22. * Constructor.
  23. *
  24. * @param Router $router A Router instance
  25. */
  26. public function __construct(Router $router)
  27. {
  28. $this->generator = $router->getGenerator();
  29. }
  30. /**
  31. * Generates a URL from the given parameters.
  32. *
  33. * @param string $name The name of the route
  34. * @param array $parameters An array of parameters
  35. * @param Boolean $absolute Whether to generate an absolute URL
  36. *
  37. * @return string The generated URL
  38. */
  39. public function generate($name, array $parameters = array(), $absolute = false)
  40. {
  41. return $this->generator->generate($name, $parameters, $absolute);
  42. }
  43. /**
  44. * Returns the canonical name of this helper.
  45. *
  46. * @return string The canonical name
  47. */
  48. public function getName()
  49. {
  50. return 'router';
  51. }
  52. }