GalleryImageFactory.php
48 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Domain\Factory\Gallery; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 6 | use AmeliaBooking\Domain\Entity\Gallery\GalleryImage; |
| 7 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 8 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\PositiveInteger; |
| 9 | use AmeliaBooking\Domain\ValueObjects\Picture; |
| 10 | use AmeliaBooking\Domain\ValueObjects\String\EntityType; |
| 11 | |
| 12 | /** |
| 13 | * Class GalleryImageFactory |
| 14 | * |
| 15 | * @package AmeliaBooking\Domain\Factory\CustomField |
| 16 | */ |
| 17 | class GalleryImageFactory |
| 18 | { |
| 19 | /** |
| 20 | * @param $data |
| 21 | * |
| 22 | * @return GalleryImage |
| 23 | * @throws InvalidArgumentException |
| 24 | */ |
| 25 | public static function create($data) |
| 26 | { |
| 27 | $galleryImage = new GalleryImage( |
| 28 | new EntityType($data['entityType']), |
| 29 | new Picture($data['pictureFullPath'], $data['pictureThumbPath']), |
| 30 | new PositiveInteger($data['position']) |
| 31 | ); |
| 32 | |
| 33 | if (isset($data['id'])) { |
| 34 | $galleryImage->setId(new Id($data['id'])); |
| 35 | } |
| 36 | |
| 37 | if (isset($data['entityId'])) { |
| 38 | $galleryImage->setEntityId(new Id($data['entityId'])); |
| 39 | } |
| 40 | |
| 41 | if (isset($data['entityType'])) { |
| 42 | $galleryImage->setEntityType(new EntityType($data['entityType'])); |
| 43 | } |
| 44 | |
| 45 | return $galleryImage; |
| 46 | } |
| 47 | } |
| 48 |