Skip to content

Commit 84a263c

Browse files
committed
BitrixSettingsDiAdapter. Опция ignore
1 parent 38a3040 commit 84a263c

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/Utils/BitrixSettingsDiAdapter.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ public function importParameters(
4848
public function importServices(ContainerBuilder $container, array $services): void
4949
{
5050
foreach ($services as $id => $service) {
51+
// Ключ ignore в описании сервиса (дабы не попадал в общий контейнер)
52+
if (array_key_exists('ignore', $service)
53+
&&
54+
$service['ignore'] === true
55+
) {
56+
continue;
57+
}
58+
5159
// Если такой сервис уже есть - игнор.
5260
if ($container->hasDefinition($id)) {
5361
continue;

tests/Cases/BitrixSettingsDiAdapterTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,27 @@ public function testImportServices() : void
133133
$this->assertSame('bar', $service->getBar(), 'Параметр bar не пробросился.');
134134
}
135135

136+
/**
137+
* Импорт сервисов. Опция ignore.
138+
*
139+
* @return void
140+
* @throws Exception
141+
*/
142+
public function testImportServicesIgnore() : void
143+
{
144+
$this->fixture = $this->loadFixture('/.settings_services.php');
145+
146+
$this->obTestObject->importServices(
147+
$this->containerBuilder,
148+
$this->fixture['services']['value']
149+
);
150+
151+
$this->assertFalse(
152+
$this->containerBuilder->has('foo.service.ignore'),
153+
'Опция Ignore не сработала.'
154+
);
155+
}
156+
136157
/**
137158
* Импорт сервисов.
138159
*

tests/Fixtures/Settings/.settings_services.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
return new SampleService();
3434
}
3535
],
36+
'foo.service.ignore' => [
37+
'constructor' => static function () {
38+
return new SampleService();
39+
},
40+
'ignore' => true
41+
],
3642
'someGoodServiceName' => [
3743
'className' => SampleWithArguments::class,
3844
'constructorParams' => ['foo', 'bar'],

0 commit comments

Comments
 (0)