RouteProvider.php 2.7 KB

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