give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Responses
/
License
/
Activate.php
give
/
vendor
/
vendor-prefixed
/
stellarwp
/
licensing-api-client
/
src
/
Responses
/
License
Last commit date
Alias
3 months ago
Listing
3 months ago
ValueObjects
3 months ago
Activate.php
3 months ago
Deactivate.php
3 months ago
DeleteActivation.php
3 months ago
RegenerateKey.php
3 months ago
StatusChange.php
3 months ago
Validate.php
3 months ago
ValidatedProductCollection.php
3 months ago
Activate.php
116 lines
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Give\Vendors\LiquidWeb\LicensingApiClient\Responses\License; |
| 4 | |
| 5 | use Give\Vendors\LiquidWeb\LicensingApiClient\Responses\Contracts\Response; |
| 6 | use Give\Vendors\LiquidWeb\LicensingApiClient\Responses\License\ValueObjects\Activation; |
| 7 | use Give\Vendors\LiquidWeb\LicensingApiClient\Responses\License\ValueObjects\ActivationEntitlement; |
| 8 | use Give\Vendors\LiquidWeb\LicensingApiClient\Responses\License\ValueObjects\LicenseSummary; |
| 9 | |
| 10 | /** |
| 11 | * Represents a license activation response. |
| 12 | * |
| 13 | * @implements Response<array{ |
| 14 | * status: string, |
| 15 | * is_valid: bool, |
| 16 | * is_production: bool, |
| 17 | * license: array{license_key: string, status: string}|null, |
| 18 | * entitlement: array{ |
| 19 | * product_slug: string, |
| 20 | * tier: string, |
| 21 | * site_limit: int, |
| 22 | * active_count: int, |
| 23 | * available: int, |
| 24 | * over_limit: bool, |
| 25 | * excess_activations: int, |
| 26 | * expiration_date: string, |
| 27 | * status: string, |
| 28 | * capabilities: list<string> |
| 29 | * }|null, |
| 30 | * activation: array{ |
| 31 | * domain: string, |
| 32 | * activated_at: string |
| 33 | * }|null |
| 34 | * }> |
| 35 | */ |
| 36 | final class Activate implements Response |
| 37 | { |
| 38 | public string $status; |
| 39 | |
| 40 | public bool $isValid; |
| 41 | |
| 42 | public bool $isProduction; |
| 43 | |
| 44 | public ?LicenseSummary $license; |
| 45 | |
| 46 | public ?ActivationEntitlement $entitlement; |
| 47 | |
| 48 | public ?Activation $activation; |
| 49 | |
| 50 | private function __construct( |
| 51 | string $status, |
| 52 | bool $isValid, |
| 53 | bool $isProduction, |
| 54 | ?LicenseSummary $license, |
| 55 | ?ActivationEntitlement $entitlement, |
| 56 | ?Activation $activation |
| 57 | ) { |
| 58 | $this->status = $status; |
| 59 | $this->isValid = $isValid; |
| 60 | $this->isProduction = $isProduction; |
| 61 | $this->license = $license; |
| 62 | $this->entitlement = $entitlement; |
| 63 | $this->activation = $activation; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @param array{ |
| 68 | * status: string, |
| 69 | * is_valid: bool, |
| 70 | * is_production?: bool, |
| 71 | * license: array{license_key: string, status: string}|null, |
| 72 | * entitlement: array{ |
| 73 | * product_slug: string, |
| 74 | * tier: string, |
| 75 | * site_limit: int, |
| 76 | * active_count: int, |
| 77 | * available: int, |
| 78 | * over_limit: bool, |
| 79 | * excess_activations: int, |
| 80 | * expiration_date: string, |
| 81 | * status: string, |
| 82 | * capabilities: list<string> |
| 83 | * }|null, |
| 84 | * activation: array{ |
| 85 | * domain: string, |
| 86 | * activated_at: string |
| 87 | * }|null |
| 88 | * } $attributes |
| 89 | */ |
| 90 | public static function from(array $attributes): self { |
| 91 | $license = $attributes['license'] ?? null; |
| 92 | $entitlement = $attributes['entitlement'] ?? null; |
| 93 | $activation = $attributes['activation'] ?? null; |
| 94 | |
| 95 | return new self( |
| 96 | $attributes['status'], |
| 97 | $attributes['is_valid'], |
| 98 | $attributes['is_production'] ?? true, |
| 99 | $license ? LicenseSummary::from($license) : null, |
| 100 | $entitlement ? ActivationEntitlement::from($entitlement) : null, |
| 101 | $activation ? Activation::from($activation) : null |
| 102 | ); |
| 103 | } |
| 104 | |
| 105 | public function toArray(): array { |
| 106 | return [ |
| 107 | 'status' => $this->status, |
| 108 | 'is_valid' => $this->isValid, |
| 109 | 'is_production' => $this->isProduction, |
| 110 | 'license' => $this->license ? $this->license->toArray() : null, |
| 111 | 'entitlement' => $this->entitlement ? $this->entitlement->toArray() : null, |
| 112 | 'activation' => $this->activation ? $this->activation->toArray() : null, |
| 113 | ]; |
| 114 | } |
| 115 | } |
| 116 |