RouteProvider.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Drupal\KernelTests;
  3. use Drupal\Core\Routing\PreloadableRouteProviderInterface;
  4. use Symfony\Cmf\Component\Routing\PagedRouteProviderInterface;
  5. use Symfony\Component\HttpFoundation\Request;
  6. /**
  7. * Rebuilds the router when the provider is instantiated.
  8. */
  9. class RouteProvider implements PreloadableRouteProviderInterface, PagedRouteProviderInterface {
  10. use \Drupal\Core\DependencyInjection\DependencySerializationTrait;
  11. /**
  12. * Loads the real route provider from the container and rebuilds the router.
  13. *
  14. * @return \Drupal\Core\Routing\PreloadableRouteProviderInterface|\Symfony\Cmf\Component\Routing\PagedRouteProviderInterface|\Symfony\Component\EventDispatcher\EventSubscriberInterface
  15. * The route provider.
  16. */
  17. protected function lazyLoadItself() {
  18. if (!isset($this->service)) {
  19. $container = \Drupal::getContainer();
  20. $this->service = $container->get('simpletest.router.route_provider');
  21. $container->get('router.builder')->rebuild();
  22. }
  23. return $this->service;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function getRouteCollectionForRequest(Request $request) {
  29. return $this->lazyLoadItself()->getRouteCollectionForRequest($request);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getRouteByName($name) {
  35. return $this->lazyLoadItself()->getRouteByName($name);
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function preLoadRoutes($names) {
  41. return $this->lazyLoadItself()->preLoadRoutes($names);
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function getRoutesByNames($names) {
  47. return $this->lazyLoadItself()->getRoutesByNames($names);
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function getCandidateOutlines(array $parts) {
  53. return $this->lazyLoadItself()->getCandidateOutlines($parts);
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function getRoutesByPattern($pattern) {
  59. return $this->lazyLoadItself()->getRoutesByPattern($pattern);
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function routeProviderRouteCompare(array $a, array $b) {
  65. return $this->lazyLoadItself()->routeProviderRouteCompare($a, $b);
  66. }
  67. /**
  68. * {@inheritdoc}
  69. */
  70. public function getAllRoutes() {
  71. return $this->lazyLoadItself()->getAllRoutes();
  72. }
  73. /**
  74. * {@inheritdoc}
  75. */
  76. public function reset() {
  77. return $this->lazyLoadItself()->reset();
  78. }
  79. /**
  80. * {@inheritdoc}
  81. */
  82. public function getRoutesPaged($offset, $length = NULL) {
  83. return $this->lazyLoadItself()->getRoutesPaged($offset, $length);
  84. }
  85. /**
  86. * {@inheritdoc}
  87. */
  88. public function getRoutesCount() {
  89. return $this->lazyLoadItself()->getRoutesCount();
  90. }
  91. }