Skip to content

Commit 3cf2f75

Browse files
[DependencyInjection] Ignore unused bindings defined by attribute
1 parent 855e29c commit 3cf2f75

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

Compiler/RegisterAutoconfigureAttributesPass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ private static function registerForAutoconfiguration(ContainerBuilder $container
8282
],
8383
],
8484
],
85-
$class->getFileName()
85+
$class->getFileName(),
86+
false
8687
);
8788
};
8889

Loader/YamlFileLoader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private function parseImports(array $content, string $file)
220220
}
221221
}
222222

223-
private function parseDefinitions(array $content, string $file)
223+
private function parseDefinitions(array $content, string $file, bool $trackBindings = true)
224224
{
225225
if (!isset($content['services'])) {
226226
return;
@@ -246,14 +246,14 @@ private function parseDefinitions(array $content, string $file)
246246
if (\is_string($service) && str_starts_with($service, '@')) {
247247
throw new InvalidArgumentException(sprintf('Type definition "%s" cannot be an alias within "_instanceof" in "%s". Check your YAML syntax.', $id, $file));
248248
}
249-
$this->parseDefinition($id, $service, $file, []);
249+
$this->parseDefinition($id, $service, $file, [], false, $trackBindings);
250250
}
251251
}
252252

253253
$this->isLoadingInstanceof = false;
254254
$defaults = $this->parseDefaults($content, $file);
255255
foreach ($content['services'] as $id => $service) {
256-
$this->parseDefinition($id, $service, $file, $defaults);
256+
$this->parseDefinition($id, $service, $file, $defaults, false, $trackBindings);
257257
}
258258
}
259259

@@ -342,7 +342,7 @@ private function isUsingShortSyntax(array $service): bool
342342
*
343343
* @throws InvalidArgumentException When tags are invalid
344344
*/
345-
private function parseDefinition(string $id, $service, string $file, array $defaults, bool $return = false)
345+
private function parseDefinition(string $id, $service, string $file, array $defaults, bool $return = false, bool $trackBindings = true)
346346
{
347347
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
348348
throw new InvalidArgumentException(sprintf('Service names that start with an underscore are reserved. Rename the "%s" service or define it in XML instead.', $id));
@@ -666,7 +666,7 @@ private function parseDefinition(string $id, $service, string $file, array $defa
666666
$bindingType = $this->isLoadingInstanceof ? BoundArgument::INSTANCEOF_BINDING : BoundArgument::SERVICE_BINDING;
667667
foreach ($bindings as $argument => $value) {
668668
if (!$value instanceof BoundArgument) {
669-
$bindings[$argument] = new BoundArgument($value, true, $bindingType, $file);
669+
$bindings[$argument] = new BoundArgument($value, $trackBindings, $bindingType, $file);
670670
}
671671
}
672672
}

Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testProcess()
3434

3535
(new RegisterAutoconfigureAttributesPass())->process($container);
3636

37-
$argument = new BoundArgument(1, true, BoundArgument::INSTANCEOF_BINDING, realpath(__DIR__.'/../Fixtures/AutoconfigureAttributed.php'));
37+
$argument = new BoundArgument(1, false, BoundArgument::INSTANCEOF_BINDING, realpath(__DIR__.'/../Fixtures/AutoconfigureAttributed.php'));
3838
$values = $argument->getValues();
3939
--$values[1];
4040
$argument->setValues($values);

0 commit comments

Comments
 (0)