A change of mindset

A change of mindset

Magento is a finished product that you extend without touching the core. That is why it has so many ways to intervene: plugins on any public method, preferences, layout XML, EAV, admin config with scopes.

Symfony is a set of components from which you assemble your own application. There is no core as a product: the code in src/ is the application, you own it and simply change it. So there are far fewer ways to intervene, and behavior is more explicit: what you see in the constructor and the configuration is what runs.

The key idea

Most Magento-style "how do I intercept X" questions turn into "just change your code" in Symfony. Interception is only needed for code in vendor/, and there are three tools for it: an event, a decorator, a service override.

Carries over almost unchanged

  • Constructor dependency injection, programming to interfaces. Magento taught you this, Symfony rewards it.
  • Composer, PSR-4, Psr\Log\LoggerInterface and Monolog are the same.
  • bin/magento is built on Symfony Console. A command class looks almost the same.
  • Thinking in events and observers.
  • Message queues, retries, separate workers.
  • PHPUnit, PHPStan, PHP-CS-Fixer.

You need to unlearn

  • ObjectManager and generated code: Factory, Proxy, Interceptor in generated/.
  • getData()/setData(), DataObject and magic getters.
  • Plugins on any method of any class.
  • XML for everything. In Symfony most configuration is PHP attributes next to the code, the rest is YAML.
  • An interface in Api/Data for every entity. Service contracts are optional here.
  • EAV, store/website scopes, admin settings, indexers, modes. They don't exist, and you shouldn't build them without a real need.