Skip to content

Commit

Permalink
BitrixSettingsDiAdapter. Опция ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
ProklUng committed Jul 15, 2021
1 parent cd25c82 commit b50d7da
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Utils/BitrixSettingsDiAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ public function importParameters(
public function importServices(ContainerBuilder $container, array $services): void
{
foreach ($services as $id => $service) {
// Ключ ignore в описании сервиса (дабы не попадал в общий контейнер)
if (array_key_exists('ignore', $service)
&&
$service['ignore'] === true
) {
continue;
}

// Если такой сервис уже есть - игнор.
if ($container->hasDefinition($id)) {
continue;
Expand Down
21 changes: 21 additions & 0 deletions tests/Cases/Utils/BitrixSettingsDiAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,27 @@ public function testImportServices() : void
$this->assertSame('bar', $service->getBar(), 'Параметр bar не пробросился.');
}

/**
* Импорт сервисов. Опция ignore.
*
* @return void
* @throws Exception
*/
public function testImportServicesIgnore() : void
{
$this->fixture = $this->loadFixture('/.settings_services.php');

$this->obTestObject->importServices(
$this->containerBuilder,
$this->fixture['services']['value']
);

$this->assertFalse(
$this->containerBuilder->has('foo.service.ignore'),
'Опция Ignore не сработала.'
);
}

/**
* Импорт сервисов.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/Settings/.settings_services.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
return new SampleService();
}
],
'foo.service.ignore' => [
'constructor' => static function () {
return new SampleService();
},
'ignore' => true
],
'someGoodServiceName' => [
'className' => SampleWithArguments::class,
'constructorParams' => ['foo', 'bar'],
Expand Down

0 comments on commit b50d7da

Please sign in to comment.