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

Skip to content

[DependencyInjection] Autowiring deprecations after upgrading to 3.3.0 #22951

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
javiereguiluz opened this issue May 30, 2017 · 9 comments
Closed

Comments

@javiereguiluz
Copy link
Member

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.3

After upgrading the Symfony Demo app to 3.3.0 final, I see these deprecations (that weren't shown in 3.3.0 RC1):

Autowiring services based on the types they implement is deprecated since
Symfony 3.3 and won’t be supported in version 4.0. You should rename (or alias)
the “security.user_password_encoder.generic” service to
“Symfony\Component\Security\Core\Encoder\UserPasswordEncoder” instead.

Autowiring services based on the types they implement is deprecated since
Symfony 3.3 and won’t be supported in version 4.0. You should rename (or alias)
the “doctrine.orm.default_entity_manager” service to
“Doctrine\ORM\EntityManager” instead.
@ogizanagi
Copy link
Contributor

I think you simply missed it using the 3.3.0-RC1 release actually. ^^ (I double-checked and it happens in both RC and stable release).

You should probably typehint over Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface in AddUserCommand.
The same goes for the entity manager: CheckRequirementsSubscriber typehints on the implementation rather than the EntityManagerInterface for which is already declared an alias.

But the question is: should we declare explicit aliases for those implementations?

@stof
Copy link
Member

stof commented May 30, 2017

Defining the alias for the interface rather than the implementation was done on purpose, to encourage people to typehint interfaces.

@weaverryan shouldn't the exception message also mention the existing supported interface autowiring to suggest changing the typehint ? I thought you added something about it.

@javiereguiluz
Copy link
Member Author

Now I'm seeing another deprecation (that was reported on Symfony Slack by other users too):

User Deprecated: The "Twig_TokenParser_Include" class is considered final.
It may change without further notice as of its next major version. You should
not extend it from "Twig_TokenParser_Embed".

javiereguiluz added a commit to symfony/demo that referenced this issue May 30, 2017
…nagi)

This PR was merged into the master branch.

Discussion
----------

Fix autowiring type deprec & use ConsoleEvents::ERROR

Relates to symfony/symfony#22951 + use `ConsoleEvents::ERROR` rather than `ConsoleEvents::EXCEPTION`

Commits
-------

4ebe39b Fix autowiring type deprec & use ConsoleEvents::ERROR
@mkalisz77
Copy link

Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "Psr\Log\LoggerInterface".

This is from my appDevDebugProjectContainer.xml (only one single place where I found autowiring-type entry)

<service id="monolog.logger" class="Symfony\Bridge\Monolog\Logger" public="false">
  <argument>app</argument>
  <call method="pushProcessor">
    <argument type="service" id="debug.log_processor"/>
  </call>
  <call method="useMicrosecondTimestamps">
    <argument>true</argument>
  </call>
  <call method="pushHandler">
    <argument type="service" id="monolog.handler.console"/>
  </call>
  <call method="pushHandler">
    <argument type="service" id="monolog.handler.main"/>
  </call>
  <autowiring-type>Psr\Log\LoggerInterface</autowiring-type>
</service>  

@xabbuh
Copy link
Member

xabbuh commented May 30, 2017

@mkalisz77 Your issue is probably solved by updating MonologBundle to 3.1 (which contains the fix from symfony/monolog-bundle#203).

@xabbuh
Copy link
Member

xabbuh commented May 30, 2017

@javiereguiluz The @final error in Twig should go away once there is a tag in Twig containing twigphp/Twig@a083db5.

@weaverryan
Copy link
Member

@weaverryan shouldn't the exception message also mention the existing supported interface autowiring to suggest changing the typehint ? I thought you added something about it.

I did have a PR with this change... but it was ultimately reverted: #22648 (comment)

The proper fix is really to change the type-hint - e.g. UserPasswordEncoder to UserPasswordEncoderInterface. But creating an alias is not a bad solution, and will be more "global" - i.e. I would have to do just one thing versus fixing 10 type-hints.

But, this did confuse me, and is now confusing other people. My proposed message looked like this:

Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint to "Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface" instead.

I believe that - at least now - we don't have a lot of context as to exactly where the type-hint is (i.e. which argument of which method).

@weaverryan
Copy link
Member

See #22999

fabpot added a commit that referenced this issue May 31, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

Better DI type deprecation message

| Q             | A
| ------------- | ---
| Branch?       | 3,3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22951
| License       | MIT
| Doc PR        | n/a

This is the most common autowiring deprecation:

```php
public function __construct(UserPasswordEncoder $encoder)
```

You *should* type-hint `UserPasswordEncoderInterface`

Current deprecation message:
> Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won’t be supported in version 4.0. You should rename (or alias) the "security.user_password_encoder.generic" service to "Symfony\Component\Security\Core\Encoder\UserPasswordEncoder" instead.

Updated message:
> Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for argument "$encoder" of method "AppBundle\Service\TestServiceSubscriber::__construct()" to "Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface" instead.

This only happens if we detect that there is a service/alias in the container (e.g. `...\UserPasswordEncoderInterface`) for the type-hint (`...\UserPasswordEncoder)`. Otherwise, if there is no correct type-hint in the container, we give the old recommendation (about aliasing).

The only complex case (of giving good directions on *where* to fix things) is with a class that implements `ServiceSubscriberInterface` (where the type-hint is in the `getSusbcribedServices()` method). In that case, the notice is:

> Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won't be supported in version 4.0. Try changing the type-hint for "Symfony\Component\Security\Core\Encoder\UserPasswordEncoder" in "AppBundle\Service\TestServiceSubscriber" to "Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface" instead.

Commits
-------

a990d5c Improving deprecation message when hitting the "deprecated type" lookup, but an alias is available
@fabpot fabpot closed this as completed May 31, 2017
sayjun0505 added a commit to sayjun0505/sym_proj that referenced this issue Apr 16, 2023
…nagi)

This PR was merged into the master branch.

Discussion
----------

Fix autowiring type deprec & use ConsoleEvents::ERROR

Relates to symfony/symfony#22951 + use `ConsoleEvents::ERROR` rather than `ConsoleEvents::EXCEPTION`

Commits
-------

4ebe39b Fix autowiring type deprec & use ConsoleEvents::ERROR
spider-yamet added a commit to spider-yamet/sym_proj that referenced this issue Apr 16, 2023
…nagi)

This PR was merged into the master branch.

Discussion
----------

Fix autowiring type deprec & use ConsoleEvents::ERROR

Relates to symfony/symfony#22951 + use `ConsoleEvents::ERROR` rather than `ConsoleEvents::EXCEPTION`

Commits
-------

4ebe39b Fix autowiring type deprec & use ConsoleEvents::ERROR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants