Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…nerBuilderContainerBuilder 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.
lukaszmakuch commentedFeb 14, 2016
@xabbuh, the white line has been removed. |
| $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.
fabpot commentedFeb 14, 2016
👍 |
fabpot commentedFeb 14, 2016
Thank you@lukaszmakuch. |
…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<?phpuse 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
[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.