|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | declare(strict_types=1); |
4 | | -/** @noinspection PhpUnusedPrivateFieldInspection */ |
5 | 4 |
|
6 | 5 | namespace Platformsh\Client\Model\Subscription; |
7 | 6 |
|
8 | | -final class SubscriptionOptions |
| 7 | +final readonly class SubscriptionOptions |
9 | 8 | { |
10 | | - private ?string $project_region; |
| 9 | + private array $options; |
11 | 10 |
|
12 | | - private ?string $project_title; |
13 | | - |
14 | | - private ?string $default_branch; |
15 | | - |
16 | | - private ?string $options_url; |
17 | | - |
18 | | - private ?array $options_custom; |
19 | | - |
20 | | - private ?string $plan; |
21 | | - |
22 | | - private ?int $environments; |
23 | | - |
24 | | - private ?int $storage; |
25 | | - |
26 | | - private ?string $owner; |
| 11 | + private function __construct(array $options) |
| 12 | + { |
| 13 | + $this->options = $options; |
| 14 | + } |
27 | 15 |
|
28 | 16 | /** |
29 | | - * @deprecated This is no longer supported. Poll the subscription instead of submitting a callback. |
| 17 | + * @param array{ |
| 18 | + * project_region: ?string, |
| 19 | + * project_title: ?string, |
| 20 | + * default_branch: ?string, |
| 21 | + * options_url: ?string, |
| 22 | + * options_custom: ?array, |
| 23 | + * plan: ?string, |
| 24 | + * environments: ?int, |
| 25 | + * storage: ?int, |
| 26 | + * organization_id: ?string, |
| 27 | + * } $options |
30 | 28 | */ |
31 | | - private ?array $activation_callback; |
32 | | - |
33 | | - private ?string $organization_id; |
34 | | - |
35 | 29 | public static function fromArray(array $options): self |
36 | 30 | { |
37 | | - $obj = new self(); |
38 | | - foreach ($options as $key => $value) { |
39 | | - if (\property_exists($obj, $key)) { |
40 | | - $obj->{$key} = $value; |
41 | | - } else { |
42 | | - throw new \InvalidArgumentException('Unknown property: ' . $key); |
43 | | - } |
44 | | - } |
45 | | - return $obj; |
| 31 | + return new self($options); |
46 | 32 | } |
47 | 33 |
|
48 | 34 | public function toArray(): array |
49 | 35 | { |
50 | | - $arr = []; |
51 | | - foreach ($this as $key => $value) { |
52 | | - if ($value !== null && $value !== 'organization_id') { |
53 | | - $arr[$key] = $value; |
54 | | - } |
55 | | - } |
56 | | - return $arr; |
| 36 | + return $this->options; |
57 | 37 | } |
58 | 38 |
|
59 | 39 | public function organizationId(): ?string |
60 | 40 | { |
61 | | - return $this->organization_id; |
| 41 | + return $this->options['organization_id'] ?? null; |
62 | 42 | } |
63 | 43 | } |
0 commit comments