CacheFactory.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @copyright © Melograno Ventures. All rights reserved. |
| 5 | * @licence See LICENCE.md for license details. |
| 6 | */ |
| 7 | |
| 8 | namespace AmeliaBooking\Domain\Factory\Cache; |
| 9 | |
| 10 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 11 | use AmeliaBooking\Domain\Entity\Cache\Cache; |
| 12 | use AmeliaBooking\Domain\ValueObjects\Json; |
| 13 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 14 | use AmeliaBooking\Domain\ValueObjects\String\Name; |
| 15 | |
| 16 | /** |
| 17 | * Class CacheFactory |
| 18 | * |
| 19 | * @package AmeliaBooking\Domain\Factory\Cache |
| 20 | */ |
| 21 | class CacheFactory |
| 22 | { |
| 23 | /** |
| 24 | * @param $data |
| 25 | * |
| 26 | * @return Cache |
| 27 | * @throws InvalidArgumentException |
| 28 | */ |
| 29 | public static function create($data) |
| 30 | { |
| 31 | $cache = new Cache( |
| 32 | new Name($data['name']) |
| 33 | ); |
| 34 | |
| 35 | if (isset($data['id'])) { |
| 36 | $cache->setId(new Id($data['id'])); |
| 37 | } |
| 38 | |
| 39 | if (!empty($data['paymentId'])) { |
| 40 | $cache->setPaymentId(new Id($data['paymentId'])); |
| 41 | } |
| 42 | |
| 43 | if (!empty($data['data'])) { |
| 44 | $cache->setData(new Json($data['data'])); |
| 45 | } |
| 46 | |
| 47 | return $cache; |
| 48 | } |
| 49 | } |
| 50 |