-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] fixed exceptions thrown by get method of ContainerBuilder #17719
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
+18
−13
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…nerBuilder ContainerBuilder was throwing more abstract exceptions than ContainerInterface. After this change, it's consistent with its interface. Done to follow the Liskov substitution principle.
Added white space between variable name and description.
$this->fail('->getDefinition() throws a ServiceNotFoundException if the service definition does not exist'); | ||
} catch (ServiceNotFoundException $e) { | ||
$this->assertEquals('You have requested a non-existent service "baz".', $e->getMessage(), '->getDefinition() throws a ServiceNotFoundException if the service definition does not exist'); | ||
|
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.
empty line too much
I removed an unnecessary empty line in the ContainerBuilderTest file.
@xabbuh, the white line has been removed. |
@@ -440,7 +442,8 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV | |||
|
|||
try { | |||
$definition = $this->getDefinition($id); | |||
} catch (InvalidArgumentException $e) { | |||
} catch (ServiceNotFoundException $e) { | |||
|
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.
This empty line should be removed.
👍 |
Thank you @lukaszmakuch. |
fabpot
added a commit
that referenced
this pull request
Feb 14, 2016
…d of ContainerBuilder (lukaszmakuch) This PR was squashed before being merged into the 2.3 branch (closes #17719). Discussion ---------- [DependencyInjection] fixed exceptions thrown by get method of ContainerBuilder [DependencyInjection] fixed exceptions thrown by get method of ContainerBuilder Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | The ContainerBuilder class wasn't implementing the ContainerInterface interface as it should according to the Liskov substitution principle. It caused dependency on implementation instead than on the interface when using an instance of the ContainerBuilder class. For example this code: ```php <?php use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Symfony\Component\DependencyInjection\ContainerInterface; /* @var $container ContainerInterface */ try { $container->get("wrong_service_key"); } catch (ServiceNotFoundException $e) { //action on a wrong key } ``` works for correct implementations of the ContainerInterface interface, but the ContainerBuilder class was breaking that by throwing more abstract exceptions. As the ServiceNotFoundException exceptions inherits from the InvalidArgumentException exception, this change shouldn't break code which catches the InvalidArgumentException exception while fetching values from a ContainerInterface interface implementation. Commits ------- aecb0fa [DependencyInjection] fixed exceptions thrown by get method of ContainerBuilder
This was referenced Feb 28, 2016
Merged
Merged
Merged
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[DependencyInjection] fixed exceptions thrown by get method of ContainerBuilder
The ContainerBuilder class wasn't implementing the ContainerInterface interface as it should according to the Liskov substitution principle.
It caused dependency on implementation instead than on the interface when using an instance of the ContainerBuilder class.
For example this code:
works for correct implementations of the ContainerInterface interface, but the ContainerBuilder class was breaking that by throwing more abstract exceptions.
As the ServiceNotFoundException exceptions inherits from the InvalidArgumentException exception, this change shouldn't break code which catches the InvalidArgumentException exception while fetching values from a ContainerInterface interface implementation.