Skip to content

[DependencyInjection] Ignore unused bindings defined by attribute #46425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ private static function registerForAutoconfiguration(ContainerBuilder $container
],
],
],
$class->getFileName()
$class->getFileName(),
false
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private function parseImports(array $content, string $file)
}
}

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

$this->isLoadingInstanceof = false;
$defaults = $this->parseDefaults($content, $file);
foreach ($content['services'] as $id => $service) {
$this->parseDefinition($id, $service, $file, $defaults);
$this->parseDefinition($id, $service, $file, $defaults, false, $trackBindings);
}
}

Expand Down Expand Up @@ -342,7 +342,7 @@ private function isUsingShortSyntax(array $service): bool
*
* @throws InvalidArgumentException When tags are invalid
*/
private function parseDefinition(string $id, $service, string $file, array $defaults, bool $return = false)
private function parseDefinition(string $id, $service, string $file, array $defaults, bool $return = false, bool $trackBindings = true)
{
if (preg_match('/^_[a-zA-Z0-9_]*$/', $id)) {
throw new InvalidArgumentException(sprintf('Service names that start with an underscore are reserved. Rename the "%s" service or define it in XML instead.', $id));
Expand Down Expand Up @@ -666,7 +666,7 @@ private function parseDefinition(string $id, $service, string $file, array $defa
$bindingType = $this->isLoadingInstanceof ? BoundArgument::INSTANCEOF_BINDING : BoundArgument::SERVICE_BINDING;
foreach ($bindings as $argument => $value) {
if (!$value instanceof BoundArgument) {
$bindings[$argument] = new BoundArgument($value, true, $bindingType, $file);
$bindings[$argument] = new BoundArgument($value, $trackBindings, $bindingType, $file);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testProcess()

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

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