8000 Merge branch 2.8 into 3.2 by GuilhemN · Pull Request #21673 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Merge branch 2.8 into 3.2 #21673

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

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[DependencyInjection] Fix autowiring collisions detection
  • Loading branch information
GuilhemN committed Feb 18, 2017
commit bb70472dce4cafe2cc425e9d6b4c05cbde7cc10b
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AutowirePass implements CompilerPassInterface
private $definedTypes = array();
private $types;
private $notGuessableTypes = array();
private $usedTypes = array();

/**
* {@inheritdoc}
Expand All @@ -44,6 +45,15 @@ public function process(ContainerBuilder $container)
$this->completeDefinition($id, $definition);
}
}

foreach ($this->usedTypes as $type => $id) {
if (isset($this->usedTypes[$type]) && isset($this->notGuessableTypes[$type])) {
$classOrInterface = class_exists($type) ? 'class' : 'interface';
$matchingServices = implode(', ', $this->types[$type]);

throw new RuntimeException(sprintf('Unable to autowire argument of type "%s" for the service "%s". Multiple services exist for this %s (%s).', $type, $id, $classOrInterface, $matchingServices));
}
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
}
Expand All @@ -56,6 +66,7 @@ public function process(ContainerBuilder $container)
$this->definedTypes = array();
$this->types = null;
$this->notGuessableTypes = array();
$this->usedTypes = array();

if (isset($e)) {
throw $e;
Expand Down Expand Up @@ -109,9 +120,11 @@ private function completeDefinition($id, Definition $definition)

if (isset($this->types[$typeHint->name]) && !isset($this->notGuessableTypes[$typeHint->name])) {
$value = new Reference($this->types[$typeHint->name]);
$this->usedTypes[$typeHint->name] = $id;
} else {
try {
$value = $this->createAutowiredDefinition($typeHint, $id);
$this->usedTypes[$typeHint->name] = $id;
} catch (RuntimeException $e) {
if ($parameter->allowsNull()) {
$value = null;
Expand Down
0