11.
Autowiring Deprecations
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
4 Comments
How do I know which one to use in this case? (it was the Symfony\Bundle\FrameworkBundle\Routing\Router )
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 "$router" of method "AppBundle\Service\Postback::__construct()" to one of its parents: interface "Symfony\Component\Routing\Matcher\UrlMatcherInterface", interface "Symfony\Component\Routing\Generator\UrlGeneratorInterface", or interface "Symfony\Component\Routing\RouterInterface".
Hey Trafficmanagertech!
Ah, great question! Can I give you 2 different answers? :)
1) They are ALL correct. All 3 interfaces will cause the correct service to be injected. So, choose your favorite!
2) (the slightly more complete answer) Whatever you choose, you just need to make sure that the method you want to call on the route (e.g. generate) is on that interface. For example, UrlMatcherInterface does *not* have a generate() method on it. Actually, your code will still work just fine (because Symfony will pass your the router service, which *does* have this method), but it will look weird to call a method on an interface that does not have that method :). So, assuming you are calling generate(), that method exists on both UrlGeneratorInterface and RouterInterface. Actually, RouterInterface simply extends both UrlGeneratorInterface and UrlMatcherInterface :p. So, you can use either RouterInterface or UrlGeneratorInterface - the second one is more "hipster" because it's a smaller, more-specific interface, but I often use RouterInterface because it's more clear (we understand what a "router" is, but a "url generator" sounds more cryptic.
Phew! Sorry for the long explanation, but I hope it helps!
Cheers!
Thank you very much :)
"I leave those as homework", such a great way of explaining things! Keep on going Ryan! :)
"Houston: no signs of life"
Start the conversation!