services.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
  12. use Symfony\Component\Config\Resource\SelfCheckingResourceChecker;
  13. use Symfony\Component\Config\ResourceCheckerConfigCacheFactory;
  14. use Symfony\Component\Console\ConsoleEvents;
  15. use Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker;
  16. use Symfony\Component\DependencyInjection\EnvVarProcessor;
  17. use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
  18. use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
  19. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  20. use Symfony\Component\DependencyInjection\ReverseContainer;
  21. use Symfony\Component\EventDispatcher\EventDispatcher;
  22. use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatcherInterfaceComponentAlias;
  23. use Symfony\Component\Filesystem\Filesystem;
  24. use Symfony\Component\Form\FormEvents;
  25. use Symfony\Component\HttpFoundation\RequestStack;
  26. use Symfony\Component\HttpFoundation\UrlHelper;
  27. use Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer;
  28. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
  29. use Symfony\Component\HttpKernel\Config\FileLocator;
  30. use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
  31. use Symfony\Component\HttpKernel\EventListener\LocaleAwareListener;
  32. use Symfony\Component\HttpKernel\HttpCache\Store;
  33. use Symfony\Component\HttpKernel\HttpKernel;
  34. use Symfony\Component\HttpKernel\HttpKernelInterface;
  35. use Symfony\Component\HttpKernel\KernelEvents;
  36. use Symfony\Component\HttpKernel\KernelInterface;
  37. use Symfony\Component\HttpKernel\UriSigner;
  38. use Symfony\Component\String\LazyString;
  39. use Symfony\Component\String\Slugger\AsciiSlugger;
  40. use Symfony\Component\String\Slugger\SluggerInterface;
  41. use Symfony\Component\Workflow\WorkflowEvents;
  42. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  43. return static function (ContainerConfigurator $container) {
  44. // this parameter is used at compile time in RegisterListenersPass
  45. $container->parameters()->set('event_dispatcher.event_aliases', array_merge(
  46. class_exists(ConsoleEvents::class) ? ConsoleEvents::ALIASES : [],
  47. class_exists(FormEvents::class) ? FormEvents::ALIASES : [],
  48. KernelEvents::ALIASES,
  49. class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : []
  50. ));
  51. $container->services()
  52. ->set('parameter_bag', ContainerBag::class)
  53. ->args([
  54. service('service_container'),
  55. ])
  56. ->alias(ContainerBagInterface::class, 'parameter_bag')
  57. ->alias(ParameterBagInterface::class, 'parameter_bag')
  58. ->set('event_dispatcher', EventDispatcher::class)
  59. ->public()
  60. ->tag('container.hot_path')
  61. ->alias(EventDispatcherInterfaceComponentAlias::class, 'event_dispatcher')
  62. ->alias(EventDispatcherInterface::class, 'event_dispatcher')
  63. ->set('http_kernel', HttpKernel::class)
  64. ->public()
  65. ->args([
  66. service('event_dispatcher'),
  67. service('controller_resolver'),
  68. service('request_stack'),
  69. service('argument_resolver'),
  70. ])
  71. ->tag('container.hot_path')
  72. ->alias(HttpKernelInterface::class, 'http_kernel')
  73. ->set('request_stack', RequestStack::class)
  74. ->public()
  75. ->alias(RequestStack::class, 'request_stack')
  76. ->set('http_cache', HttpCache::class)
  77. ->args([
  78. service('kernel'),
  79. service('http_cache.store'),
  80. service('esi')->nullOnInvalid(),
  81. abstract_arg('options'),
  82. ])
  83. ->tag('container.hot_path')
  84. ->set('http_cache.store', Store::class)
  85. ->args([
  86. param('kernel.cache_dir').'/http_cache',
  87. ])
  88. ->set('url_helper', UrlHelper::class)
  89. ->args([
  90. service('request_stack'),
  91. service('router.request_context')->ignoreOnInvalid(),
  92. ])
  93. ->alias(UrlHelper::class, 'url_helper')
  94. ->set('cache_warmer', CacheWarmerAggregate::class)
  95. ->public()
  96. ->args([
  97. tagged_iterator('kernel.cache_warmer'),
  98. param('kernel.debug'),
  99. sprintf('%s/%sDeprecations.log', param('kernel.build_dir'), param('kernel.container_class')),
  100. ])
  101. ->tag('container.no_preload')
  102. ->set('cache_clearer', ChainCacheClearer::class)
  103. ->public()
  104. ->args([
  105. tagged_iterator('kernel.cache_clearer'),
  106. ])
  107. ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2'])
  108. ->set('kernel')
  109. ->synthetic()
  110. ->public()
  111. ->alias(KernelInterface::class, 'kernel')
  112. ->set('filesystem', Filesystem::class)
  113. ->public()
  114. ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2'])
  115. ->alias(Filesystem::class, 'filesystem')
  116. ->set('file_locator', FileLocator::class)
  117. ->args([
  118. service('kernel'),
  119. ])
  120. ->alias(FileLocator::class, 'file_locator')
  121. ->set('uri_signer', UriSigner::class)
  122. ->args([
  123. param('kernel.secret'),
  124. ])
  125. ->alias(UriSigner::class, 'uri_signer')
  126. ->set('config_cache_factory', ResourceCheckerConfigCacheFactory::class)
  127. ->args([
  128. tagged_iterator('config_cache.resource_checker'),
  129. ])
  130. ->set('dependency_injection.config.container_parameters_resource_checker', ContainerParametersResourceChecker::class)
  131. ->args([
  132. service('service_container'),
  133. ])
  134. ->tag('config_cache.resource_checker', ['priority' => -980])
  135. ->set('config.resource.self_checking_resource_checker', SelfCheckingResourceChecker::class)
  136. ->tag('config_cache.resource_checker', ['priority' => -990])
  137. ->set('services_resetter', ServicesResetter::class)
  138. ->public()
  139. ->set('reverse_container', ReverseContainer::class)
  140. ->args([
  141. service('service_container'),
  142. service_locator([]),
  143. ])
  144. ->alias(ReverseContainer::class, 'reverse_container')
  145. ->set('locale_aware_listener', LocaleAwareListener::class)
  146. ->args([
  147. [], // locale aware services
  148. service('request_stack'),
  149. ])
  150. ->tag('kernel.event_subscriber')
  151. ->set('container.env_var_processor', EnvVarProcessor::class)
  152. ->args([
  153. service('service_container'),
  154. tagged_iterator('container.env_var_loader'),
  155. ])
  156. ->tag('container.env_var_processor')
  157. ->set('slugger', AsciiSlugger::class)
  158. ->args([
  159. param('kernel.default_locale'),
  160. ])
  161. ->tag('kernel.locale_aware')
  162. ->alias(SluggerInterface::class, 'slugger')
  163. ->set('container.getenv', \Closure::class)
  164. ->factory([\Closure::class, 'fromCallable'])
  165. ->args([
  166. [service('service_container'), 'getEnv'],
  167. ])
  168. ->tag('routing.expression_language_function', ['function' => 'env'])
  169. // inherit from this service to lazily access env vars
  170. ->set('container.env', LazyString::class)
  171. ->abstract()
  172. ->factory([LazyString::class, 'fromCallable'])
  173. ->args([
  174. service('container.getenv'),
  175. ])
  176. ;
  177. };