Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed

Conversation

@lukaszmakuch
Copy link

[DependencyInjection] fixed exceptions thrown by get method of ContainerBuilder

QA
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
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:

<?phpuseSymfony\Component\DependencyInjection\Exception\ServiceNotFoundException;useSymfony\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.

…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');

Copy link
Contributor

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
Copy link
Author

@xabbuh, the white line has been removed.

$definition =$this->getDefinition($id);
}catch (InvalidArgumentException$e) {
}catch (ServiceNotFoundException$e) {

Copy link
Member

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
Copy link
Member

👍

@fabpot
Copy link
Member

Thank you@lukaszmakuch.

fabpot added a commit that referenced this pull requestFeb 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<?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
@fabpotfabpot closed thisFeb 14, 2016
This was referencedFeb 28, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@lukaszmakuch@fabpot@Tobion@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp