give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Responses
/
Entitlement
/
Upsert.php
give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Responses
/
Entitlement
Last commit date
ValueObjects
3 months ago
Cancel.php
3 months ago
Delete.php
3 months ago
Suspend.php
3 months ago
SwitchTier.php
3 months ago
Unsuspend.php
3 months ago
Upsert.php
3 months ago
Upsert.php
58 lines
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Give\Vendors\LiquidWeb\LicensingApiClient\Responses\Entitlement; |
| 4 | |
| 5 | use Give\Vendors\LiquidWeb\LicensingApiClient\Responses\Contracts\Response; |
| 6 | use Give\Vendors\LiquidWeb\LicensingApiClient\Responses\Entitlement\ValueObjects\UpsertProduct; |
| 7 | |
| 8 | /** |
| 9 | * Represents an entitlement upsert response payload. |
| 10 | * |
| 11 | * @phpstan-import-type ResponseProductPayload from UpsertProduct |
| 12 | * |
| 13 | * @implements Response<array{ |
| 14 | * license_key: string, |
| 15 | * products: list<ResponseProductPayload> |
| 16 | * }> |
| 17 | */ |
| 18 | final class Upsert implements Response |
| 19 | { |
| 20 | public string $licenseKey; |
| 21 | |
| 22 | /** |
| 23 | * @var UpsertProduct[] |
| 24 | */ |
| 25 | public array $products; |
| 26 | |
| 27 | /** |
| 28 | * @param UpsertProduct[] $products |
| 29 | */ |
| 30 | private function __construct(string $licenseKey, array $products) { |
| 31 | $this->licenseKey = $licenseKey; |
| 32 | $this->products = $products; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @param array{license_key: string, products: list<ResponseProductPayload>} $attributes |
| 37 | */ |
| 38 | public static function from(array $attributes): self { |
| 39 | return new self( |
| 40 | $attributes['license_key'], |
| 41 | array_map( |
| 42 | static fn (array $product): UpsertProduct => UpsertProduct::from($product), |
| 43 | $attributes['products'] |
| 44 | ) |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | public function toArray(): array { |
| 49 | return [ |
| 50 | 'license_key' => $this->licenseKey, |
| 51 | 'products' => array_map( |
| 52 | static fn (UpsertProduct $product): array => $product->toArray(), |
| 53 | $this->products |
| 54 | ), |
| 55 | ]; |
| 56 | } |
| 57 | } |
| 58 |