Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Challenges building complex applications with Symfony2

Challenges building complex applications with Symfony2

Symfony2 ecosystem provides us with convenient ways of getting the job done. Over time conveniences like base controller, service locator, doctrine base repository and others promotes tight coupling becoming and obstacle in the development. We will focus on practical examples on how to make our code more domain focused and less dependent on Symfony2 ecosystem.

Eduardo Oliveira

May 15, 2014
Tweet

More Decks by Eduardo Oliveira

Other Decks in Programming

Transcript

  1. Why I can talk about PHP and Symfony2? Note: The

    high number of deletes is due to delete PHPdoc generated docs. A MQ, no Symfony2 on this just PHP and Redis. … …
  2. Doesn’t fit ! • CRUD applications • Simple applications, go

    with RAD approach instead • You are on it just for the money • Prototype (make sure you don’t ship it)
  3. A new Symfony2 project Starts with the dream to write:

    ! • elegant code • code that you are proud • reusable code
  4. Typical form/entity • High coupling (UI and domain) • Mixed

    concerns (same validation UI and domain) • Domain entities can be constructed in an invalid state
  5. Typical repository • Magic • Domain coupled to infrastructure, not

    to a contract • No idea what queries your application run
  6. Entities & Doctrine ORM • Data mapper (entity unaware of

    persistence) • No need for setters/getters, Doctrine uses Reflection • You own the object constructor
  7. Entities & Doctrine ORM recipe Try VO’s support, if doesn’t

    fit in your use case don’t use Doctrine ORM 
 it will hurt too much your code. ! You can still and should use Doctrine DBAL.
  8. Controllers recipe • Controllers as services • Don’t use service

    locator • Don’t extend the Symfony2 base controller • Group your dependencies and inject them
  9. Forms • The Symfony2 component more loved/ hated • Integrates

    well with validation • You can control construction with empty_data • It requires getters
  10. Forms recipe ! • Don’t bind forms to domain entities

    • Add specific entities to support the presentation layer • Use Symfony validations on presentation • Use Forms as services
  11. Repositories recipe ! Don’t use the base Doctrine repository !

    Want to know more? https://github.com/entering/doctrine- repository