CustomFieldOptionFactory.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Domain\Factory\CustomField; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 6 | use AmeliaBooking\Domain\Entity\CustomField\CustomFieldOption; |
| 7 | use AmeliaBooking\Domain\ValueObjects\Json; |
| 8 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 9 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\IntegerValue; |
| 10 | use AmeliaBooking\Domain\ValueObjects\String\Label; |
| 11 | |
| 12 | /** |
| 13 | * Class CustomFieldOptionFactory |
| 14 | * |
| 15 | * @package AmeliaBooking\Domain\Factory\CustomField |
| 16 | */ |
| 17 | class CustomFieldOptionFactory |
| 18 | { |
| 19 | /** |
| 20 | * @param $data |
| 21 | * |
| 22 | * @return CustomFieldOption |
| 23 | * @throws InvalidArgumentException |
| 24 | */ |
| 25 | public static function create($data) |
| 26 | { |
| 27 | $customFieldOption = new CustomFieldOption( |
| 28 | new Id($data['customFieldId']), |
| 29 | new Label($data['label']), |
| 30 | new IntegerValue($data['position']) |
| 31 | ); |
| 32 | |
| 33 | if (isset($data['translations'])) { |
| 34 | $customFieldOption->setTranslations(new Json($data['translations'])); |
| 35 | } |
| 36 | |
| 37 | if (isset($data['id'])) { |
| 38 | $customFieldOption->setId(new Id($data['id'])); |
| 39 | } |
| 40 | |
| 41 | return $customFieldOption; |
| 42 | } |
| 43 | } |
| 44 |