Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid setters using Symfony with admin panel creator?

I want to avoid getters/setters hell in my entities (here is the reason: http://ocramius.github.io/doctrine-best-practices/#/53), but both most popular admin panel generators:

  • Sonata and DoctrineORMAdminBundle
  • https://github.com/javiereguiluz/EasyAdminBundle

need getters and setters to render view.

My idea is to create DTO object instead (http://ocramius.github.io/doctrine-best-practices/#/57) and then use named constructors to create entities. I want to call named constructor inside my service. What is the best way to force admin panel generators to use my DTOs to persist/update data, can you give me an idea and/or example of good practices in that case?

The only way I imagined is to use DTO instead of real Entity, call prePersist/preUpdate hooks and use custom service, but it looks confusing.

like image 891
Dawid Dominiak Avatar asked Feb 08 '16 14:02

Dawid Dominiak


1 Answers

One of the most important aspect of DDD is to correctly identify your bounded contexts (usually aligned with your sub-domains) and determine the appropriate technologies and architectures to use within those.

An admin panel sounds like something generic that would be very CRUD in nature. If that's the case then don't try to fight it and embrace CRUD within that BC. Trying to implement a pure domain model in a BC where it isn't needed would make things more complicated than they need to be.

However, if you determined that the complexity justifies a domain model then I would advise against using a code generator. Properly modeling the reality of a complex domain is not an easy task, and certainly not one that could be achieved by a tool.

like image 159
plalx Avatar answered Oct 03 '22 18:10

plalx