Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. <?php
  2.  
  3. namespace JuanPescador\Domain\Person\Command;
  4.  
  5. use IctWorks\SharedKernel\Domain\Service\TimeService;
  6. use IctWorks\SharedKernel\Domain\ValueObject\Email;
  7. use IctWorks\SharedKernel\Domain\ValueObject\Language;
  8. use IctWorks\SharedKernel\Domain\ValueObject\PersonName;
  9. use IctWorks\SharedKernel\Domain\ValueObject\PhoneNumber;
  10. use IctWorks\SharedKernel\ReadModel\DTO\FileDTO;
  11. use JMS\Serializer\Annotation as Serializer;
  12. use JuanPescador\Domain\MessageBuilder;
  13. use JuanPescador\Domain\Person\Gender;
  14. use JuanPescador\Domain\Person\PersonType;
  15. use JuanPescador\Domain\Person\PictureFactory;
  16. use Ramsey\Uuid\Uuid;
  17. use JMS\DiExtraBundle\Annotation as DI;
  18.  
  19. /**
  20. * Class RegisterPersonCommandBuilder
  21. * @package JuanPescador\Domain\Person\Command
  22. * @author Dariusz Gafka <dgafka.mail@gmail.com>
  23. *
  24. * @DI\Service()
  25. * @DI\Tag(name="injectable", attributes={"to"="message_builder_from_string", "index"="0"})
  26. */
  27. class RegisterPersonMessageBuilder implements MessageBuilder
  28. {
  29. private const MESSAGE_NAME = "juan_pescador.command.person.register";
  30.  
  31. /**
  32. * @var PictureFactory
  33. */
  34. private $pictureFactory;
  35.  
  36. /**
  37. * @var TimeService
  38. */
  39. private $timeService;
  40.  
  41. /**
  42. * @var string
  43. *
  44. * @Serializer\Type("string")
  45. */
  46. protected $personId;
  47.  
  48. /**
  49. * @var string
  50. *
  51. * @Serializer\Type("string")
  52. */
  53. protected $email;
  54. /**
  55. * @var string
  56. *
  57. * @Serializer\Type("string")
  58. */
  59. protected $firstName;
  60. /**
  61. * @var string
  62. *
  63. * @Serializer\Type("string")
  64. */
  65. protected $middleName;
  66. /**
  67. * @var string
  68. *
  69. * @Serializer\Type("string")
  70. */
  71. protected $lastName;
  72. /**
  73. * @var string
  74. *
  75. * @Serializer\Type("string")
  76. */
  77. protected $dateOfBirth;
  78. /**
  79. * @var string
  80. *
  81. * @Serializer\Type("string")
  82. * @Serializer\SerializedName("phonenumber")
  83. */
  84. protected $phoneNumber;
  85. /**
  86. * @var string
  87. *
  88. * @Serializer\Type("string")
  89. */
  90. private $gender;
  91. /**
  92. * @var FileDTO
  93. * @Serializer\Type("IctWorks\SharedKernel\ReadModel\DTO\FileDTO")
  94. */
  95. private $picture;
  96. /**
  97. * @var string
  98. *
  99. * @Serializer\Type("string")
  100. */
  101. private $primaryLanguage;
  102.  
  103. /**
  104. * RegisterPersonCommandBuilder constructor.
  105. *
  106. * @param PictureFactory $pictureFactory
  107. * @param TimeService $timeService
  108. *
  109. * @DI\InjectParams({
  110. * "pictureFactory" = @DI\Inject("juan_pescador.domain.person.picture_factory"),
  111. * "timeService" = @DI\Inject("ict_works.shared_kernel.domain.service.time_service")
  112. * })
  113. */
  114. public function __construct(PictureFactory $pictureFactory, TimeService $timeService)
  115. {
  116. $this->pictureFactory = $pictureFactory;
  117. $this->timeService = $timeService;
  118. }
  119.  
  120. /**
  121. * @inheritDoc
  122. */
  123. public function build()
  124. {
  125. $picture = $this->picture ? $this->pictureFactory->createWith($this->personId, $this->picture->extension(), $this->picture->content(), $this->picture->fileName()) : null;
  126. $dateOfBirth = $this->dateOfBirth ? $this->timeService->createImmutableDateTime($this->dateOfBirth) : null;
  127.  
  128. return new RegisterPersonCommand(
  129. Uuid::fromString($this->personId),
  130. Email::createWith($this->email),
  131. PersonType::create(PersonType::NONE),
  132. new PersonName($this->firstName, $this->middleName, $this->lastName),
  133. Gender::create($this->gender),
  134. Language::create($this->primaryLanguage),
  135. $this->phoneNumber ? PhoneNumber::createWith($this->phoneNumber) : null,
  136. $picture,
  137. $dateOfBirth
  138. );
  139. }
  140.  
  141. /**
  142. * @inheritDoc
  143. */
  144. public function handles(string $messageName): bool
  145. {
  146. return self::MESSAGE_NAME === $messageName;
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement