22
33namespace Prokl \ServiceProvider \Utils ;
44
5- use Symfony \Component \DependencyInjection \ContainerInterface ;
6- use Symfony \Component \DependencyInjection \Definition ;
5+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
76
87/**
98 * Class BitrixSettingsDiAdapter
@@ -16,19 +15,20 @@ class BitrixSettingsDiAdapter
1615 /**
1716 * Импортировать параметры из .settings.php
1817 *
19- * @param ContainerInterface $container Контейнер.
20- * @param array $settings Секция parameters .settings.php.
21- * @param string|null $section Если задано, то параметры попадут в отдельную секцию контейнера.
18+ * @param ContainerBuilder $container Контейнер.
19+ * @param array $settings Секция parameters .settings.php.
20+ * @param string|null $section Если задано, то параметры попадут в отдельную секцию контейнера.
2221 *
2322 * @return void
2423 */
2524 public function importParameters (
26- ContainerInterface $ container ,
25+ ContainerBuilder $ container ,
2726 array $ settings ,
2827 ?string $ section = null
29- ) : void {
28+ ): void {
3029 if ($ section !== null ) {
3130 $ container ->setParameter ($ section , $ settings );
31+
3232 return ;
3333 }
3434
@@ -40,19 +40,23 @@ public function importParameters(
4040 /**
4141 * Импортировать сервисы из .settings.php.
4242 *
43- * @param ContainerInterface $container Контейнер.
44- * @param array $services Секция services .settings.php.
43+ * @param ContainerBuilder $container Контейнер.
44+ * @param array $services Секция services .settings.php.
4545 *
4646 * @return void
4747 */
48- public function importServices (ContainerInterface $ container , array $ services ) : void
48+ public function importServices (ContainerBuilder $ container , array $ services ): void
4949 {
5050 foreach ($ services as $ id => $ service ) {
51+ // Если такой сервис уже есть - игнор.
52+ if ($ container ->hasDefinition ($ id )) {
53+ continue ;
54+ }
55+
5156 if (array_key_exists ('constructor ' , $ service )
5257 &&
5358 is_callable ($ service ['constructor ' ])
5459 ) {
55- /** @var Definition $definition */
5660 $ definition = $ container ->register ($ id , FactoryClosure::class);
5761 $ definition ->setFactory ([FactoryClosure::class, 'from ' ]);
5862 $ definition ->addArgument ($ service ['constructor ' ]);
0 commit comments