Skip to content

Commit

Permalink
BitrixSettingsDiAdapter. Запрет повторной регистрации сервисов.
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jul 13, 2021
1 parent 1cdf839 commit a058a64
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/Utils/BitrixSettingsDiAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace Prokl\ServiceProvider\Utils;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Class BitrixSettingsDiAdapter
Expand All @@ -16,19 +15,20 @@ class BitrixSettingsDiAdapter
/**
* Импортировать параметры из .settings.php
*
* @param ContainerInterface $container Контейнер.
* @param array $settings Секция parameters .settings.php.
* @param string|null $section Если задано, то параметры попадут в отдельную секцию контейнера.
* @param ContainerBuilder $container Контейнер.
* @param array $settings Секция parameters .settings.php.
* @param string|null $section Если задано, то параметры попадут в отдельную секцию контейнера.
*
* @return void
*/
public function importParameters(
ContainerInterface $container,
ContainerBuilder $container,
array $settings,
?string $section = null
) : void {
): void {
if ($section !== null) {
$container->setParameter($section, $settings);

return;
}

Expand All @@ -40,19 +40,23 @@ public function importParameters(
/**
* Импортировать сервисы из .settings.php.
*
* @param ContainerInterface $container Контейнер.
* @param array $services Секция services .settings.php.
* @param ContainerBuilder $container Контейнер.
* @param array $services Секция services .settings.php.
*
* @return void
*/
public function importServices(ContainerInterface $container, array $services) : void
public function importServices(ContainerBuilder $container, array $services): void
{
foreach ($services as $id => $service) {
// Если такой сервис уже есть - игнор.
if ($container->hasDefinition($id)) {
continue;
}

if (array_key_exists('constructor', $service)
&&
is_callable($service['constructor'])
) {
/** @var Definition $definition */
$definition = $container->register($id, FactoryClosure::class);
$definition->setFactory([FactoryClosure::class, 'from']);
$definition->addArgument($service['constructor']);
Expand Down

0 comments on commit a058a64

Please sign in to comment.