GoogleCalendarFactory.php
54 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 | * @param $data |
| 20 | * |
| 21 | * @return GoogleCalendar |
| 22 | * @throws InvalidArgumentException |
| 23 | */ |
| 24 | public static function create($data) |
| 25 | { |
| 26 | $googleCalendar = new GoogleCalendar( |
| 27 | new Token($data['token']), |
| 28 | new Name(empty($data['calendarId']) ? null : $data['calendarId']) |
| 29 | ); |
| 30 | |
| 31 | if (isset($data['id'])) { |
| 32 | $googleCalendar->setId(new Id($data['id'])); |
| 33 | } |
| 34 | |
| 35 | if (isset($data['insertPendingAppointments'])) { |
| 36 | $googleCalendar->setInsertPendingAppointments((bool)$data['insertPendingAppointments']); |
| 37 | } |
| 38 | |
| 39 | if (isset($data['includeBufferTime'])) { |
| 40 | $googleCalendar->setIncludeBufferTime((bool)$data['includeBufferTime']); |
| 41 | } |
| 42 | |
| 43 | if (isset($data['title'])) { |
| 44 | $googleCalendar->setTitle($data['title']); |
| 45 | } |
| 46 | |
| 47 | if (isset($data['description'])) { |
| 48 | $googleCalendar->setDescription($data['description']); |
| 49 | } |
| 50 | |
| 51 | return $googleCalendar; |
| 52 | } |
| 53 | } |
| 54 |