DEV Community

Discussion on: Domain Driven Design with PHP and Symfony

Collapse
 
ludofleury profile image
Ludovic Fleury • Edited

You can do whatever you want! its your implem :)

usually we do not use setter in the "domain" because we do not "set state", a specific process/feature change the state of something.

Yet in command, you can do whatever you want. Its a DTO: en.wikipedia.org/wiki/Data_transfe...

So its just structured data. In my implementation, I use command as a frontier/boundary between user input (weak) & model layer (strong).

So:

  • you always pass primitive to the command (creation).
  • you always get (value) object from the command (usage/execution).

Example: I don't give a DateTime object to my command, I give a date string "2020/01/01" and I get a DateTimeImmutable object from my command.

Why ? because, if you pass it from HTTP or CLI, the user input is a string.

Which brings 2 validations concerns: the input validation and model validation:

  1. I create the command with the date string
  2. I ensure the string looks like a valide date (input validation)
  3. I get the DateTimeImmutable object from my command in my handler (and validate that the date is logic with the requirement of my application)

OR

  1. I get a "Birthday" value object which encapsulate a DateTimeImmutable object (if needed) and in the constructor of this VO, I check that the person is not 350 years old, or at least 18 (according to the requirement of my domain)