77use Exception ;
88use InvalidArgumentException ;
99use Prokl \ServiceProvider \Bundles \BundlesLoader ;
10+ use Prokl \ServiceProvider \Framework \AutoconfigureConfig ;
1011use Prokl \ServiceProvider \Framework \SymfonyCompilerPassBag ;
1112use Prokl \ServiceProvider \Services \AppKernel ;
1213use Prokl \ServiceProvider \Utils \ErrorScreen ;
1314use Psr \Container \ContainerInterface ;
1415use Psr \Container \ContainerInterface as PsrContainerInterface ;
1516use RuntimeException ;
1617use Symfony \Bridge \ProxyManager \LazyProxy \PhpDumper \ProxyDumper ;
17- use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
1818use Symfony \Component \Config \ConfigCache ;
1919use Symfony \Component \Config \Loader \DelegatingLoader ;
2020use Symfony \Component \Config \Loader \LoaderInterface ;
3131use Symfony \Component \DependencyInjection \Loader \PhpFileLoader ;
3232use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
3333use Symfony \Component \DependencyInjection \Loader \YamlFileLoader ;
34- use Symfony \Component \DependencyInjection \ServiceLocator ;
3534use Symfony \Component \EventDispatcher \DependencyInjection \RegisterListenersPass ;
3635use Symfony \Component \EventDispatcher \EventDispatcher ;
37- use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
3836use Symfony \Component \Filesystem \Exception \IOExceptionInterface ;
3937use Symfony \Component \Filesystem \Filesystem ;
40- use Symfony \Component \HttpKernel \Controller \ArgumentValueResolverInterface ;
4138use Symfony \Component \HttpKernel \KernelEvents ;
42- use Symfony \Component \Validator \ConstraintValidatorInterface ;
43- use Symfony \Component \Validator \ObjectInitializerInterface ;
4439
4540/**
4641 * Class ServiceProvider
6358 * @since 04.04.2021 Вынес стандартные compile pass Symfony в отдельный класс.
6459 * @since 14.04.2021 Метод boot бандлов вызывается теперь после компиляции контейнера.
6560 * @since 27.04.2021 Баг-фикс: при скомпилированном контейнере не запускался метод boot бандлов.
61+ * @since 26.06.2021 Автоконфигурация тэгов вынесена в отдельный метод.
6662 *
6763 * @psalm-consistent-constructor
6864 */
@@ -336,6 +332,7 @@ private function initContainer(string $fileName)
336332 }
337333
338334 // Подключение скомпилированного контейнера.
335+ /** @noinspection PhpIncludeInspection */
339336 require_once $ compiledContainerFile ;
340337
341338 $ classCompiledContainerName = '\\' .$ classCompiledContainerName ;
@@ -474,6 +471,7 @@ private function loadContainer(string $fileName)
474471 static ::$ containerBuilder ->addCompilerPass ($ pass );
475472 }
476473
474+ $ this ->registerAutoconfig ();
477475 $ this ->standartSymfonyPasses ();
478476
479477 // Локальные compile pass.
@@ -628,7 +626,7 @@ private function getPathCacheDirectory(string $filename) : string
628626 }
629627
630628 /**
631- * Стандартные Symfony манипуляции над контейнером .
629+ * Compiler passes .
632630 *
633631 * @return void
634632 *
@@ -638,21 +636,6 @@ private function getPathCacheDirectory(string $filename) : string
638636 */
639637 private function standartSymfonyPasses (): void
640638 {
641- /** @var array $autoConfigure Автоконфигурация тэгов. */
642- $ autoConfigure = [
643- 'controller.service_arguments ' => AbstractController::class,
644- 'controller.argument_value_resolver ' => ArgumentValueResolverInterface::class,
645- 'container.service_locator ' => ServiceLocator::class,
646- 'kernel.event_subscriber ' => EventSubscriberInterface::class,
647- 'validator.constraint_validator ' => ConstraintValidatorInterface::class,
648- 'validator.initializer ' => ObjectInitializerInterface::class,
649- ];
650-
651- foreach ($ autoConfigure as $ tag => $ class ) {
652- static ::$ containerBuilder ->registerForAutoconfiguration ($ class )
653- ->addTag ($ tag );
654- }
655-
656639 // Применяем compiler passes.
657640 foreach ($ this ->standartCompilerPasses as $ pass ) {
658641 if (!array_key_exists ('pass ' , $ pass ) || !class_exists ($ pass ['pass ' ])) {
@@ -665,6 +648,22 @@ private function standartSymfonyPasses(): void
665648 }
666649 }
667650
651+ /**
652+ * Регистрация автоконфигурируемых тэгов.
653+ *
654+ * @return void
655+ * @throws RuntimeException Когда необходимая зависимость не существует.
656+ */
657+ private function registerAutoconfig () : void
658+ {
659+ $ autoConfigure = new AutoconfigureConfig ();
660+
661+ foreach ($ autoConfigure ->getAutoConfigure () as $ tag => $ class ) {
662+ static ::$ containerBuilder ->registerForAutoconfiguration ($ class )
663+ ->addTag ($ tag );
664+ }
665+ }
666+
668667 /**
669668 * Загрузка "автономных" бандлов Symfony.
670669 *
0 commit comments