Closed MarioBlazek closed 4 years ago
Service definitions are necessary because Symfony requires the value of array to be proper PHP type.
This won't work:
return [
'service_id' => 'service_id',
];
Alright :+1:
Btw, don't we need an entry in NetgenEzPlatformSiteApiExtension
to load autowiring.yml
?
No, the main service.yml file has:
imports:
- { resource: services/*.yml }
Ok, I'm apparently blind :D I was looking at the file and couldn't see it !
Awesome, thanks @MarioBlazek!
This PR allows controllers to be autowired, which means that explicit service definition for a controller is not required anymore. By default SiteAPI controller extends the AbstractController which implements ServiceSubscriberInterface with the set of necessary services. We need to expand getSubscribedServices() method with services that are necessary for the Site API controller.
The use case we want to achieve. Custom view controller without service definition:
Without this code, calling $this->getSite() would result in this error: