routing.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  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 Symfony\Component\DependencyInjection\Loader\Configurator;
  11. use Psr\Container\ContainerInterface;
  12. use Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer;
  13. use Symfony\Bundle\FrameworkBundle\Controller\RedirectController;
  14. use Symfony\Bundle\FrameworkBundle\Controller\TemplateController;
  15. use Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader;
  16. use Symfony\Bundle\FrameworkBundle\Routing\RedirectableCompiledUrlMatcher;
  17. use Symfony\Bundle\FrameworkBundle\Routing\Router;
  18. use Symfony\Component\Config\Loader\LoaderResolver;
  19. use Symfony\Component\HttpKernel\EventListener\RouterListener;
  20. use Symfony\Component\Routing\Generator\CompiledUrlGenerator;
  21. use Symfony\Component\Routing\Generator\Dumper\CompiledUrlGeneratorDumper;
  22. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  23. use Symfony\Component\Routing\Loader\ContainerLoader;
  24. use Symfony\Component\Routing\Loader\DirectoryLoader;
  25. use Symfony\Component\Routing\Loader\GlobFileLoader;
  26. use Symfony\Component\Routing\Loader\PhpFileLoader;
  27. use Symfony\Component\Routing\Loader\XmlFileLoader;
  28. use Symfony\Component\Routing\Loader\YamlFileLoader;
  29. use Symfony\Component\Routing\Matcher\Dumper\CompiledUrlMatcherDumper;
  30. use Symfony\Component\Routing\Matcher\ExpressionLanguageProvider;
  31. use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
  32. use Symfony\Component\Routing\RequestContext;
  33. use Symfony\Component\Routing\RequestContextAwareInterface;
  34. use Symfony\Component\Routing\RouterInterface;
  35. return static function (ContainerConfigurator $container) {
  36. $container->parameters()
  37. ->set('router.request_context.host', 'localhost')
  38. ->set('router.request_context.scheme', 'http')
  39. ->set('router.request_context.base_url', '')
  40. ;
  41. $container->services()
  42. ->set('routing.resolver', LoaderResolver::class)
  43. ->set('routing.loader.xml', XmlFileLoader::class)
  44. ->args([
  45. service('file_locator'),
  46. ])
  47. ->tag('routing.loader')
  48. ->set('routing.loader.yml', YamlFileLoader::class)
  49. ->args([
  50. service('file_locator'),
  51. ])
  52. ->tag('routing.loader')
  53. ->set('routing.loader.php', PhpFileLoader::class)
  54. ->args([
  55. service('file_locator'),
  56. ])
  57. ->tag('routing.loader')
  58. ->set('routing.loader.glob', GlobFileLoader::class)
  59. ->args([
  60. service('file_locator'),
  61. ])
  62. ->tag('routing.loader')
  63. ->set('routing.loader.directory', DirectoryLoader::class)
  64. ->args([
  65. service('file_locator'),
  66. ])
  67. ->tag('routing.loader')
  68. ->set('routing.loader.container', ContainerLoader::class)
  69. ->args([
  70. tagged_locator('routing.route_loader'),
  71. ])
  72. ->tag('routing.loader')
  73. ->set('routing.loader', DelegatingLoader::class)
  74. ->public()
  75. ->args([
  76. service('routing.resolver'),
  77. [], // Default options
  78. [], // Default requirements
  79. ])
  80. ->set('router.default', Router::class)
  81. ->args([
  82. service(ContainerInterface::class),
  83. param('router.resource'),
  84. [
  85. 'cache_dir' => param('kernel.cache_dir'),
  86. 'debug' => param('kernel.debug'),
  87. 'generator_class' => CompiledUrlGenerator::class,
  88. 'generator_dumper_class' => CompiledUrlGeneratorDumper::class,
  89. 'matcher_class' => RedirectableCompiledUrlMatcher::class,
  90. 'matcher_dumper_class' => CompiledUrlMatcherDumper::class,
  91. ],
  92. service('router.request_context')->ignoreOnInvalid(),
  93. service('parameter_bag')->ignoreOnInvalid(),
  94. service('logger')->ignoreOnInvalid(),
  95. param('kernel.default_locale'),
  96. ])
  97. ->call('setConfigCacheFactory', [
  98. service('config_cache_factory'),
  99. ])
  100. ->tag('monolog.logger', ['channel' => 'router'])
  101. ->tag('container.service_subscriber', ['id' => 'routing.loader'])
  102. ->alias('router', 'router.default')
  103. ->public()
  104. ->alias(RouterInterface::class, 'router')
  105. ->alias(UrlGeneratorInterface::class, 'router')
  106. ->alias(UrlMatcherInterface::class, 'router')
  107. ->alias(RequestContextAwareInterface::class, 'router')
  108. ->set('router.request_context', RequestContext::class)
  109. ->factory([RequestContext::class, 'fromUri'])
  110. ->args([
  111. param('router.request_context.base_url'),
  112. param('router.request_context.host'),
  113. param('router.request_context.scheme'),
  114. param('request_listener.http_port'),
  115. param('request_listener.https_port'),
  116. ])
  117. ->call('setParameter', [
  118. '_functions',
  119. service('router.expression_language_provider')->ignoreOnInvalid(),
  120. ])
  121. ->alias(RequestContext::class, 'router.request_context')
  122. ->set('router.expression_language_provider', ExpressionLanguageProvider::class)
  123. ->args([
  124. tagged_locator('routing.expression_language_function', 'function'),
  125. ])
  126. ->tag('routing.expression_language_provider')
  127. ->set('router.cache_warmer', RouterCacheWarmer::class)
  128. ->args([service(ContainerInterface::class)])
  129. ->tag('container.service_subscriber', ['id' => 'router'])
  130. ->tag('kernel.cache_warmer')
  131. ->set('router_listener', RouterListener::class)
  132. ->args([
  133. service('router'),
  134. service('request_stack'),
  135. service('router.request_context')->ignoreOnInvalid(),
  136. service('logger')->ignoreOnInvalid(),
  137. param('kernel.project_dir'),
  138. param('kernel.debug'),
  139. ])
  140. ->tag('kernel.event_subscriber')
  141. ->tag('monolog.logger', ['channel' => 'request'])
  142. ->set(RedirectController::class)
  143. ->public()
  144. ->args([
  145. service('router'),
  146. inline_service('int')
  147. ->factory([service('router.request_context'), 'getHttpPort']),
  148. inline_service('int')
  149. ->factory([service('router.request_context'), 'getHttpsPort']),
  150. ])
  151. ->set(TemplateController::class)
  152. ->args([
  153. service('twig')->ignoreOnInvalid(),
  154. ])
  155. ->public()
  156. ;
  157. };