annotations.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 Doctrine\Common\Annotations\AnnotationReader;
  12. use Doctrine\Common\Annotations\AnnotationRegistry;
  13. use Doctrine\Common\Annotations\CachedReader;
  14. use Doctrine\Common\Annotations\Reader;
  15. use Symfony\Bundle\FrameworkBundle\CacheWarmer\AnnotationsCacheWarmer;
  16. use Symfony\Component\Cache\Adapter\ArrayAdapter;
  17. use Symfony\Component\Cache\Adapter\FilesystemAdapter;
  18. use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
  19. use Symfony\Component\Cache\DoctrineProvider;
  20. return static function (ContainerConfigurator $container) {
  21. $container->services()
  22. ->set('annotations.reader', AnnotationReader::class)
  23. ->call('addGlobalIgnoredName', [
  24. 'required',
  25. service('annotations.dummy_registry'), // dummy arg to register class_exists as annotation loader only when required
  26. ])
  27. ->set('annotations.dummy_registry', AnnotationRegistry::class)
  28. ->call('registerUniqueLoader', ['class_exists'])
  29. ->set('annotations.cached_reader', CachedReader::class)
  30. ->args([
  31. service('annotations.reader'),
  32. inline_service(DoctrineProvider::class)->args([
  33. inline_service(ArrayAdapter::class)
  34. ]),
  35. abstract_arg('Debug-Flag'),
  36. ])
  37. ->set('annotations.filesystem_cache_adapter', FilesystemAdapter::class)
  38. ->args([
  39. '',
  40. 0,
  41. abstract_arg('Cache-Directory'),
  42. ])
  43. ->set('annotations.filesystem_cache', DoctrineProvider::class)
  44. ->args([
  45. service('annotations.filesystem_cache_adapter'),
  46. ])
  47. ->set('annotations.cache_warmer', AnnotationsCacheWarmer::class)
  48. ->args([
  49. service('annotations.reader'),
  50. param('kernel.cache_dir').'/annotations.php',
  51. '#^Symfony\\\\(?:Component\\\\HttpKernel\\\\|Bundle\\\\FrameworkBundle\\\\Controller\\\\(?!.*Controller$))#',
  52. param('kernel.debug'),
  53. ])
  54. ->set('annotations.cache', DoctrineProvider::class)
  55. ->args([
  56. inline_service(PhpArrayAdapter::class)
  57. ->factory([PhpArrayAdapter::class, 'create'])
  58. ->args([
  59. param('kernel.cache_dir').'/annotations.php',
  60. service('cache.annotations'),
  61. ]),
  62. ])
  63. ->tag('container.hot_path')
  64. ->alias('annotation_reader', 'annotations.reader')
  65. ->alias(Reader::class, 'annotation_reader');
  66. };