Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace JuanPescador\Domain\Person\Command;
- use IctWorks\SharedKernel\Domain\Service\TimeService;
- use IctWorks\SharedKernel\Domain\ValueObject\Email;
- use IctWorks\SharedKernel\Domain\ValueObject\Language;
- use IctWorks\SharedKernel\Domain\ValueObject\PersonName;
- use IctWorks\SharedKernel\Domain\ValueObject\PhoneNumber;
- use IctWorks\SharedKernel\ReadModel\DTO\FileDTO;
- use JMS\Serializer\Annotation as Serializer;
- use JuanPescador\Domain\MessageBuilder;
- use JuanPescador\Domain\Person\Gender;
- use JuanPescador\Domain\Person\PersonType;
- use JuanPescador\Domain\Person\PictureFactory;
- use Ramsey\Uuid\Uuid;
- use JMS\DiExtraBundle\Annotation as DI;
- /**
- * Class RegisterPersonCommandBuilder
- * @package JuanPescador\Domain\Person\Command
- * @author Dariusz Gafka <dgafka.mail@gmail.com>
- *
- * @DI\Service()
- * @DI\Tag(name="injectable", attributes={"to"="message_builder_from_string", "index"="0"})
- */
- class RegisterPersonMessageBuilder implements MessageBuilder
- {
- private const MESSAGE_NAME = "juan_pescador.command.person.register";
- /**
- * @var PictureFactory
- */
- private $pictureFactory;
- /**
- * @var TimeService
- */
- private $timeService;
- /**
- * @var string
- *
- * @Serializer\Type("string")
- */
- protected $personId;
- /**
- * @var string
- *
- * @Serializer\Type("string")
- */
- protected $email;
- /**
- * @var string
- *
- * @Serializer\Type("string")
- */
- protected $firstName;
- /**
- * @var string
- *
- * @Serializer\Type("string")
- */
- protected $middleName;
- /**
- * @var string
- *
- * @Serializer\Type("string")
- */
- protected $lastName;
- /**
- * @var string
- *
- * @Serializer\Type("string")
- */
- protected $dateOfBirth;
- /**
- * @var string
- *
- * @Serializer\Type("string")
- * @Serializer\SerializedName("phonenumber")
- */
- protected $phoneNumber;
- /**
- * @var string
- *
- * @Serializer\Type("string")
- */
- private $gender;
- /**
- * @var FileDTO
- * @Serializer\Type("IctWorks\SharedKernel\ReadModel\DTO\FileDTO")
- */
- private $picture;
- /**
- * @var string
- *
- * @Serializer\Type("string")
- */
- private $primaryLanguage;
- /**
- * RegisterPersonCommandBuilder constructor.
- *
- * @param PictureFactory $pictureFactory
- * @param TimeService $timeService
- *
- * @DI\InjectParams({
- * "pictureFactory" = @DI\Inject("juan_pescador.domain.person.picture_factory"),
- * "timeService" = @DI\Inject("ict_works.shared_kernel.domain.service.time_service")
- * })
- */
- public function __construct(PictureFactory $pictureFactory, TimeService $timeService)
- {
- $this->pictureFactory = $pictureFactory;
- $this->timeService = $timeService;
- }
- /**
- * @inheritDoc
- */
- public function build()
- {
- $picture = $this->picture ? $this->pictureFactory->createWith($this->personId, $this->picture->extension(), $this->picture->content(), $this->picture->fileName()) : null;
- $dateOfBirth = $this->dateOfBirth ? $this->timeService->createImmutableDateTime($this->dateOfBirth) : null;
- return new RegisterPersonCommand(
- Uuid::fromString($this->personId),
- Email::createWith($this->email),
- PersonType::create(PersonType::NONE),
- new PersonName($this->firstName, $this->middleName, $this->lastName),
- Gender::create($this->gender),
- Language::create($this->primaryLanguage),
- $this->phoneNumber ? PhoneNumber::createWith($this->phoneNumber) : null,
- $picture,
- $dateOfBirth
- );
- }
- /**
- * @inheritDoc
- */
- public function handles(string $messageName): bool
- {
- return self::MESSAGE_NAME === $messageName;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement