GoogleCalendarFactory.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Domain\Factory\Google; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 6 | use AmeliaBooking\Domain\Entity\Google\GoogleCalendar; |
| 7 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 8 | use AmeliaBooking\Domain\ValueObjects\String\Name; |
| 9 | use AmeliaBooking\Domain\ValueObjects\String\Token; |
| 10 | |
| 11 | /** |
| 12 | * Class GoogleCalendarFactory |
| 13 | * |
| 14 | * @package AmeliaBooking\Domain\Factory\Google |
| 15 | */ |
| 16 | class GoogleCalendarFactory |
| 17 | { |
| 18 | |
| 19 | /** |
| 20 | * @param $data |
| 21 | * |
| 22 | * @return GoogleCalendar |
| 23 | * @throws InvalidArgumentException |
| 24 | */ |
| 25 | public static function create($data) |
| 26 | { |
| 27 | $googleCalendar = new GoogleCalendar( |
| 28 | new Token($data['token']), |
| 29 | new Name(empty($data['calendarId']) ? null : $data['calendarId']) |
| 30 | ); |
| 31 | |
| 32 | if (isset($data['id'])) { |
| 33 | $googleCalendar->setId(new Id($data['id'])); |
| 34 | } |
| 35 | |
| 36 | return $googleCalendar; |
| 37 | } |
| 38 | } |
| 39 |