Symfony best practices

Always prefer Subscribers instead of Event Listeners.
- Event Listeners must be explicitly configured in config file in order to add
tag
andset
event to listen to. - Subscriber can define to which event to subscribe inside of class method
EventSubscriberInterface::getSubscribedEvents
. - Listener method names are build by convention (onKernelException), which is not obvious behavior.
You should use Event Listener only for 3rd party code and if you have option to choose, which event to listen for.
You don't need access to Service Container directly, so mark each service as public: false
in order to restrict access to them directly and inject them in appropriate places only.
Keep thin controllers and implement all domain-related logic inside dedicated services. If possible try not to extend AbstractController
in order not to couple with a framework (conflicts with Symfony best practices). You can use kernel.view event to transform custom response object to Symfony Response
. Suffix Action
is not required for controller method names.
Do not use $container->get()
to fetch services from container. You should configure DI container to inject required services and values to the appropriate services via Dependency Injection.
Do not use Symfony Forms with entities. Use DTO instead.