NullGenerator.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Drupal\Core\Routing;
  3. use Drupal\Core\Render\BubbleableMetadata;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Symfony\Component\Routing\RequestContext as SymfonyRequestContext;
  6. use Symfony\Component\Routing\Exception\RouteNotFoundException;
  7. use Symfony\Component\Routing\Route;
  8. /**
  9. * No-op implementation of a Url Generator, needed for backward compatibility.
  10. */
  11. class NullGenerator extends UrlGenerator {
  12. /**
  13. * Override the parent constructor.
  14. *
  15. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
  16. * The request stack.
  17. */
  18. public function __construct(RequestStack $request_stack) {
  19. $this->requestStack = $request_stack;
  20. $this->context = new RequestContext();
  21. }
  22. /**
  23. * {@inheritdoc}
  24. *
  25. * Methods generate(), generateFromRoute() and getPathFromRoute() all call
  26. * this protected method.
  27. */
  28. protected function getRoute($name) {
  29. if ($name === '<front>') {
  30. return new Route('/');
  31. }
  32. elseif ($name === '<current>') {
  33. return new Route($this->requestStack->getCurrentRequest()->getPathInfo());
  34. }
  35. elseif ($name === '<none>') {
  36. return new Route('');
  37. }
  38. throw new RouteNotFoundException();
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function processRoute($name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL) {
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. protected function getInternalPathFromRoute($name, Route $route, $parameters = [], &$query_params = []) {
  49. return $route->getPath();
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function setContext(SymfonyRequestContext $context) {
  55. }
  56. /**
  57. * {@inheritdoc}
  58. */
  59. public function getContext() {
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. protected function processPath($path, &$options = [], BubbleableMetadata $bubbleable_metadata = NULL) {
  65. return $path;
  66. }
  67. }