Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI] Don't throw Autowire exception for removed service with private __construct #22991

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

Merged
merged 1 commit into from
May 31, 2017

Conversation

weaverryan
Copy link
Member

Q A
Branch? 3.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none (was talking to a user)
License MIT
Doc PR n/a

Suppose you have:

class A
{
    private function construct() {}
}

This service will fail to be autowired. But, like other autowiring failures, if this service will ultimately be removed from the container, this exception should be ignored. This fixes that. Unless someone is using the AutowirePass directly inside a try/catch, there is no BC break (the behavior change is that the exception is now stored, instead of being thrown).

This also clarifies (in the test & phpdoc) that AutowirePass always throws AutowiringFailedExceptions.

Thanks!

…service was removed

The specific report was for a service with a private constructor. This also clarifies
that the AutowirePass throws AutowiringFailedException for all situations. And a bug
was fixed in the constructor of AutowiringFailedException
@weaverryan weaverryan force-pushed the allow-private-constructor-autowiring branch from 83ff14c to 2d3e44e Compare May 31, 2017 13:52
@weaverryan
Copy link
Member Author

Fabbot failure is false

@MetalArend
Copy link
Contributor

That was fast! Thanks for fixing this!

@fabpot
Copy link
Member

fabpot commented May 31, 2017

Thank you @weaverryan.

@fabpot fabpot merged commit 2d3e44e into symfony:3.3 May 31, 2017
fabpot added a commit that referenced this pull request May 31, 2017
…th private __construct (weaverryan)

This PR was merged into the 3.3 branch.

Discussion
----------

[DI] Don't throw Autowire exception for removed service with private __construct

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none (was talking to a user)
| License       | MIT
| Doc PR        | n/a

Suppose you have:

```php
class A
{
    private function construct() {}
}
```

This service will fail to be autowired. But, like other autowiring failures, if this service will ultimately be removed from the container, this exception should be ignored. This fixes that. Unless someone is using the `AutowirePass` directly inside a `try/catch`, there is no BC break (the behavior change is that the exception is now stored, instead of being thrown).

This also clarifies (in the test & phpdoc) that `AutowirePass` always throws `AutowiringFailedException`s.

Thanks!

Commits
-------

2d3e44e Fixing a bug where an autowiring exception was thrown even when that service was removed
@weaverryan weaverryan deleted the allow-private-constructor-autowiring branch May 31, 2017 17:57
@fabpot fabpot mentioned this pull request Jun 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants