CustomerEntity.php
3 months ago
CustomerFactory.php
1 month ago
CustomerStatus.php
3 years ago
index.php
3 years ago
CustomerFactory.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Membership\Models\Customer; |
| 4 | |
| 5 | use ProfilePress\Core\Membership\Models\FactoryInterface; |
| 6 | use ProfilePress\Core\Membership\Repositories\CustomerRepository; |
| 7 | |
| 8 | class CustomerFactory implements FactoryInterface |
| 9 | { |
| 10 | /** |
| 11 | * @param $data |
| 12 | * |
| 13 | * @return CustomerEntity |
| 14 | */ |
| 15 | public static function make($data) |
| 16 | { |
| 17 | return new CustomerEntity($data); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * @param $id |
| 22 | * |
| 23 | * @return CustomerEntity |
| 24 | */ |
| 25 | public static function fromId($id) |
| 26 | { |
| 27 | return ppress_cache_transform('customer_factory_from_id_' . $id, function () use ($id) { |
| 28 | return CustomerRepository::init()->retrieve(absint($id)); |
| 29 | }); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @param $user_id |
| 34 | * |
| 35 | * @return CustomerEntity |
| 36 | */ |
| 37 | public static function fromUserId($user_id) |
| 38 | { |
| 39 | return ppress_cache_transform('customer_factory_from_user_id_' . $user_id, function () use ($user_id) { |
| 40 | return CustomerRepository::init()->retrieveByUserID(absint($user_id)); |
| 41 | }); |
| 42 | } |
| 43 | } |