symfony / demo

Symfony Demo Application
https://symfony.com/
MIT License
2.46k stars 1.61k forks source link

[Streamlining Entity Design] Introducing the DTOs #1522

Open yceruto opened 2 months ago

yceruto commented 2 months ago

I've made some updates to our entity designs to match what the community recommends about Forms -> DTOs -> Entities.

So, the Post entity is now separate from input/request processing, which is handled by the new PostDto. I updated all Post's properties to meet business rules about nullability. For example, since the Post title is required, it’s no longer nullable. This also let me remove the phpstan exceptions about Entity <-> DB mapping mismatches.

I kept things simple on purpose, but we might think about adding required properties in the constructor later (or through semantic constructors) to avoid invalid states.

These changes are only for the Post entity so far. If you like them, let me know, and I can update the rest.

I'll add comments to clarify any changes that might not be immediately obvious.

Cheers!