LocationFactory.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Domain\Factory\Location; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 6 | use AmeliaBooking\Domain\Entity\Location\Location; |
| 7 | use AmeliaBooking\Domain\ValueObjects\Json; |
| 8 | use AmeliaBooking\Domain\ValueObjects\String\Status; |
| 9 | use AmeliaBooking\Domain\ValueObjects\Picture; |
| 10 | use AmeliaBooking\Domain\ValueObjects\String\Address; |
| 11 | use AmeliaBooking\Domain\ValueObjects\String\Description; |
| 12 | use AmeliaBooking\Domain\ValueObjects\GeoTag; |
| 13 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 14 | use AmeliaBooking\Domain\ValueObjects\String\Name; |
| 15 | use AmeliaBooking\Domain\ValueObjects\String\Phone; |
| 16 | use AmeliaBooking\Domain\ValueObjects\String\Url; |
| 17 | |
| 18 | /** |
| 19 | * Class LocationFactory |
| 20 | * |
| 21 | * @package AmeliaBooking\Domain\Factory\Location |
| 22 | */ |
| 23 | class LocationFactory |
| 24 | { |
| 25 | |
| 26 | /** |
| 27 | * @param $data |
| 28 | * |
| 29 | * @return Location |
| 30 | * @throws InvalidArgumentException |
| 31 | */ |
| 32 | public static function create($data) |
| 33 | { |
| 34 | $location = new Location(); |
| 35 | |
| 36 | if (isset($data['id'])) { |
| 37 | $location->setId(new Id($data['id'])); |
| 38 | } |
| 39 | |
| 40 | if (isset($data['name'])) { |
| 41 | $location->setName(new Name($data['name'])); |
| 42 | } |
| 43 | |
| 44 | if (isset($data['address'])) { |
| 45 | $location->setAddress(new Address($data['address'])); |
| 46 | } |
| 47 | |
| 48 | if (isset($data['phone'])) { |
| 49 | $location->setPhone(new Phone($data['phone'])); |
| 50 | } |
| 51 | |
| 52 | if (isset($data['latitude'], $data['longitude'])) { |
| 53 | $location->setCoordinates(new GeoTag($data['latitude'], $data['longitude'])); |
| 54 | } |
| 55 | |
| 56 | if (isset($data['description'])) { |
| 57 | $location->setDescription(new Description($data['description'])); |
| 58 | } |
| 59 | |
| 60 | if (isset($data['status'])) { |
| 61 | $location->setStatus(new Status($data['status'])); |
| 62 | } |
| 63 | |
| 64 | if (!empty($data['pictureFullPath']) && !empty($data['pictureThumbPath'])) { |
| 65 | $location->setPicture(new Picture($data['pictureFullPath'], $data['pictureThumbPath'])); |
| 66 | } |
| 67 | |
| 68 | if (isset($data['pin'])) { |
| 69 | $location->setPin(new Url($data['pin'])); |
| 70 | } |
| 71 | |
| 72 | if (!empty($data['translations'])) { |
| 73 | $location->setTranslations(new Json($data['translations'])); |
| 74 | } |
| 75 | |
| 76 | return $location; |
| 77 | } |
| 78 | } |
| 79 |