BlockTimeFactory.php
2 months ago
DayOffFactory.php
5 years ago
PeriodFactory.php
2 years ago
PeriodLocationFactory.php
3 years ago
PeriodServiceFactory.php
7 years ago
SpecialDayFactory.php
7 years ago
SpecialDayPeriodFactory.php
2 years ago
SpecialDayPeriodLocationFactory.php
3 years ago
SpecialDayPeriodServiceFactory.php
7 years ago
TimeOutFactory.php
7 years ago
WeekDayFactory.php
7 years ago
PeriodFactory.php
47 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Domain\Factory\Schedule; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Collection\Collection; |
| 6 | use AmeliaBooking\Domain\Entity\Schedule\Period; |
| 7 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 8 | use AmeliaBooking\Domain\ValueObjects\DateTime\DateTimeValue; |
| 9 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 10 | use AmeliaBooking\Infrastructure\Licence; |
| 11 | |
| 12 | /** |
| 13 | * Class PeriodFactory |
| 14 | * |
| 15 | * @package AmeliaBooking\Domain\Factory\Schedule |
| 16 | */ |
| 17 | class PeriodFactory |
| 18 | { |
| 19 | /** |
| 20 | * @param array $data |
| 21 | * |
| 22 | * @return Period |
| 23 | * @throws InvalidArgumentException |
| 24 | */ |
| 25 | public static function create($data) |
| 26 | { |
| 27 | Licence\DataModifier::periodFactory($data); |
| 28 | |
| 29 | $period = new Period( |
| 30 | new DateTimeValue(\DateTime::createFromFormat('H:i:s', $data['startTime'])), |
| 31 | new DateTimeValue(\DateTime::createFromFormat('H:i:s', $data['endTime'])), |
| 32 | new Collection($data['periodServiceList']), |
| 33 | new Collection($data['periodLocationList']) |
| 34 | ); |
| 35 | |
| 36 | if (isset($data['id'])) { |
| 37 | $period->setId(new Id($data['id'])); |
| 38 | } |
| 39 | |
| 40 | if (isset($data['locationId'])) { |
| 41 | $period->setLocationId(new Id($data['locationId'])); |
| 42 | } |
| 43 | |
| 44 | return $period; |
| 45 | } |
| 46 | } |
| 47 |