Skip to content

[DI] Handle container.autowiring.strict_mode to opt-out from legacy autowiring #24671

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
Oct 24, 2017
Merged
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 @@ -34,6 +34,7 @@ class AutowirePass extends AbstractRecursivePass
private $lastFailure;
private $throwOnAutowiringException;
private $autowiringExceptions = array();
private $strictMode;

/**
* @param bool $throwOnAutowireException Errors can be retrieved via Definition::getErrors()
Expand Down Expand Up @@ -62,6 +63,7 @@ public function process(ContainerBuilder $container)
{
// clear out any possibly stored exceptions from before
$this->autowiringExceptions = array();
$this->strictMode = $container->hasParameter('container.autowiring.strict_mode') && $container->getParameter('container.autowiring.strict_mode');

try {
parent::process($container);
Expand Down Expand Up @@ -290,7 +292,7 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe
return new TypedReference($this->types[$type], $type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we have a deprecation warning triggered here, to tell people to register the type for the new system rather than relying on old types (as you disable the loading in strict mode)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They will get an exception saying that. Not sure there is anything else needed.

Copy link
Member Author

@nicolas-grekas nicolas-grekas Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof I re-enabled by-explicit-autowiring-type in strict mode, that should address your concern, isn't it?

}

if (isset($this->types[$type])) {
if (!$this->strictMode && isset($this->types[$type])) {
$message = 'Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won\'t be supported in version 4.0.';
if ($aliasSuggestion = $this->getAliasesSuggestionForType($type = $reference->getType(), $deprecationMessage)) {
$message .= ' '.$aliasSuggestion;
Expand All @@ -311,7 +313,9 @@ private function getAutowiredReference(TypedReference $reference, $deprecationMe
return $this->autowired[$type] ? new TypedReference($this->autowired[$type], $type) : null;
}

return $this->createAutowiredDefinition($type);
if (!$this->strictMode) {
return $this->createAutowiredDefinition($type);
}
}

/**
Expand Down