-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[DependencyInjection] Adding an exception on circular reference #28452
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\DependencyInjection\Exception; | ||
|
||
/** | ||
* This exception is thrown when a circular reference is detected between services in arguments. | ||
* | ||
* @author Nicolas LEFEVRE <weblefevre@gmail.com> | ||
*/ | ||
class ArgumentCircularReferenceException extends RuntimeException | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we want this to make it into a bug fix release, we should not add any new class in the PR (otherwise that'd be a smell for a new feature). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, throwing |
||
{ | ||
private $argument; | ||
private $serviceId; | ||
|
||
public function __construct($argument, $serviceId, \Exception $previous = null) | ||
{ | ||
parent::__construct(sprintf('Circular reference detected between service "%s" and parent argument "%s". A "ChildDefinition" can\'t references itself as parent.', $argument, $serviceId), 0, $previous); | ||
|
||
$this->argument = $argument; | ||
$this->serviceId = $serviceId; | ||
} | ||
|
||
public function getArgument() | ||
{ | ||
return $this->argument; | ||
} | ||
|
||
public function getServiceId() | ||
{ | ||
return $this->serviceId; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest moving the logic to
ResolveChildDefinitionsPass
.Also, can't the loop involve intermediary ids? A => B => C => A?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your feedback.
I can move it to
ResolveInstanceofConditionalsPass
(here), but I think it's not a good option too...Currently I can't find the way to move it to
ResolveChildDefinitionsPass
. If you have an idea...