{"action":"created","issue":{"url":"https://api.github.com/repos/webdevilopers/php-ddd/issues/14","repository_url":"https://api.github.com/repos/webdevilopers/php-ddd","labels_url":"https://api.github.com/repos/webdevilopers/php-ddd/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/webdevilopers/php-ddd/issues/14/comments","events_url":"https://api.github.com/repos/webdevilopers/php-ddd/issues/14/events","html_url":"https://github.com/webdevilopers/php-ddd/issues/14","id":158339616,"number":14,"title":"Primitive types only in command","user":{"login":"webdevilopers","id":3479626,"avatar_url":"https://avatars.githubusercontent.com/u/3479626?v=3","gravatar_id":"","url":"https://api.github.com/users/webdevilopers","html_url":"https://github.com/webdevilopers","followers_url":"https://api.github.com/users/webdevilopers/followers","following_url":"https://api.github.com/users/webdevilopers/following{/other_user}","gists_url":"https://api.github.com/users/webdevilopers/gists{/gist_id}","starred_url":"https://api.github.com/users/webdevilopers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webdevilopers/subscriptions","organizations_url":"https://api.github.com/users/webdevilopers/orgs","repos_url":"https://api.github.com/users/webdevilopers/repos","events_url":"https://api.github.com/users/webdevilopers/events{/privacy}","received_events_url":"https://api.github.com/users/webdevilopers/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/webdevilopers/php-ddd/labels/Application%20Layer","name":"Application Layer","color":"d93f0b"},{"url":"https://api.github.com/repos/webdevilopers/php-ddd/labels/CQRS","name":"CQRS","color":"f9d0c4"},{"url":"https://api.github.com/repos/webdevilopers/php-ddd/labels/Symfony%20Forms","name":"Symfony Forms","color":"bfdadc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-03T10:39:53Z","updated_at":"2016-06-15T19:25:08Z","closed_at":null,"body":"When I started decoupling from Symfony Form and the `EntityType` I switched to primitive types only that would then be used on the `data_class` which is the Command / DTO.\r\n\r\nIn conlusion my command only uses integers (for IDs) and strings (also UUID) or arrays of these types.\r\n\r\nI'm sometimes asked if objects e.g. value objects should be used. As I mentioned I don't use objects in a DTO at all. As @jeremyb states in his slides:\r\n\r\n> Tips #3: Command & Value Object\r\n\r\n    Il est recommandé d'utiliser des types primitifs si la Command doit être traitée en asynchrone (à cause de la serialization)\r\n    Passer des Values Objects à une Command permet de réutiliser un cadre et les validations définies\r\n\r\n* http://jeremybarthe.com/slides/2016-after-work-ddd-command-bus/#/32\r\n\r\nMost examples I see follow these \"guidelines\":\r\nhttps://github.com/SimpleBus/MessageBus/blob/master/doc/command_bus.md#using-the-command-bus-an-example @matthiasnoback\r\n\r\nSometimes a DTO property transfers a string coming from a constant:\r\n```php\r\nclass ContractState\r\n{\r\n    const STATE_ACCEPTED        = 'contract_accepted';\r\n    const STATE_APPROVED        = 'contract_approved';\r\n    const STATE_QUOTE_SUBMITTED = 'quote_submitted';\r\n    const STATE_IN_PROGRESS     = 'in_progress';\r\n    const STATE_PENDING         = 'pending';\r\n    const STATE_CLOSED          = 'closed';\r\n}\r\n```\r\n\r\nPeople ask how to ensure (validate) that the string `$contractState` of the DTO is a correct string from the constants.\r\n\r\nIf you are using Symfony Form you already set the choices and a user cannot select a different choice.\r\n\r\nWhen the input comes directly from the Request I guess you could add a custom Constraint to the Command that could check if the strings exists:\r\n* http://jeremybarthe.com/slides/2016-after-work-ddd-command-bus/#/12\r\n\r\nSince I'm using Symfony Form I prefer validating the input inside the Value Object. The handler will try to create an object from String:\r\n```php\r\nContractState::fromString($command->contractState());\r\n```\r\n\r\nThe `fromString` method then will throw an Exception if the string was invalid.\r\n\r\nWhat are your thoughts on this?\r\n\r\nRelated issues:\r\n* https://github.com/webdevilopers/php-ddd/issues/5"},"comment":{"url":"https://api.github.com/repos/webdevilopers/php-ddd/issues/comments/226293266","html_url":"https://github.com/webdevilopers/php-ddd/issues/14#issuecomment-226293266","issue_url":"https://api.github.com/repos/webdevilopers/php-ddd/issues/14","id":226293266,"user":{"login":"webdevilopers","id":3479626,"avatar_url":"https://avatars.githubusercontent.com/u/3479626?v=3","gravatar_id":"","url":"https://api.github.com/users/webdevilopers","html_url":"https://github.com/webdevilopers","followers_url":"https://api.github.com/users/webdevilopers/followers","following_url":"https://api.github.com/users/webdevilopers/following{/other_user}","gists_url":"https://api.github.com/users/webdevilopers/gists{/gist_id}","starred_url":"https://api.github.com/users/webdevilopers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/webdevilopers/subscriptions","organizations_url":"https://api.github.com/users/webdevilopers/orgs","repos_url":"https://api.github.com/users/webdevilopers/repos","events_url":"https://api.github.com/users/webdevilopers/events{/privacy}","received_events_url":"https://api.github.com/users/webdevilopers/received_events","type":"User","site_admin":false},"created_at":"2016-06-15T19:25:08Z","updated_at":"2016-06-15T19:25:08Z","body":"What about `date`s? Should they be passed as `ImmutableDateTime` objects or as primitive strings?\r\nWhat do you think @matthiasnoback?"}}
{"actor":{"display_login":"webdevilopers"}}