|
4 | 4 |
|
5 | 5 | namespace CasParser; |
6 | 6 |
|
7 | | -class RequestOptions |
| 7 | +use CasParser\Core\Attributes\Api as Property; |
| 8 | +use CasParser\Core\Concerns\SdkModel; |
| 9 | +use CasParser\Core\Contracts\BaseModel; |
| 10 | +use CasParser\Core\Implementation\Omittable; |
| 11 | +use Psr\Http\Client\ClientInterface; |
| 12 | +use Psr\Http\Message\RequestFactoryInterface; |
| 13 | +use Psr\Http\Message\StreamFactoryInterface; |
| 14 | +use Psr\Http\Message\UriFactoryInterface; |
| 15 | + |
| 16 | +use const CasParser\Core\OMIT as omit; |
| 17 | + |
| 18 | +/** |
| 19 | + * @phpstan-type request_options = array{ |
| 20 | + * timeout?: float|null, |
| 21 | + * maxRetries?: int|null, |
| 22 | + * initialRetryDelay?: float|null, |
| 23 | + * maxRetryDelay?: float|null, |
| 24 | + * extraHeaders?: array<string, string|int|null|list<string|int>>|null, |
| 25 | + * extraQueryParams?: array<string, mixed>|null, |
| 26 | + * extraBodyParams?: mixed, |
| 27 | + * transporter?: ClientInterface|null, |
| 28 | + * uriFactory?: UriFactoryInterface|null, |
| 29 | + * streamFactory?: StreamFactoryInterface|null, |
| 30 | + * requestFactory?: RequestFactoryInterface|null, |
| 31 | + * } |
| 32 | + * @phpstan-type request_opts = null|RequestOptions|request_options |
| 33 | + */ |
| 34 | +final class RequestOptions implements BaseModel |
8 | 35 | { |
9 | | - public const DEFAULT_TIMEOUT = 60; |
| 36 | + /** @use SdkModel<request_options> */ |
| 37 | + use SdkModel; |
10 | 38 |
|
11 | | - public const DEFAULT_MAX_RETRIES = 2; |
| 39 | + #[Property] |
| 40 | + public float $timeout = 60; |
12 | 41 |
|
13 | | - public const DEFAULT_INITIAL_RETRYDELAY = 0.5; |
| 42 | + #[Property] |
| 43 | + public int $maxRetries = 2; |
14 | 44 |
|
15 | | - public const DEFAULT_MAX_RETRY_DELAY = 8.0; |
| 45 | + #[Property] |
| 46 | + public float $initialRetryDelay = 0.5; |
16 | 47 |
|
17 | | - /** |
18 | | - * @param list<string> $extraHeaders |
19 | | - * @param list<string> $extraQueryParams |
20 | | - * @param list<string> $extraBodyParams |
21 | | - */ |
22 | | - public function __construct( |
23 | | - public float $timeout = self::DEFAULT_TIMEOUT, |
24 | | - public int $maxRetries = self::DEFAULT_MAX_RETRIES, |
25 | | - public float $initialRetryDelay = self::DEFAULT_INITIAL_RETRYDELAY, |
26 | | - public float $maxRetryDelay = self::DEFAULT_MAX_RETRY_DELAY, |
27 | | - public array $extraHeaders = [], |
28 | | - public array $extraQueryParams = [], |
29 | | - public array $extraBodyParams = [], |
30 | | - ) {} |
| 48 | + #[Property] |
| 49 | + public float $maxRetryDelay = 8.0; |
31 | 50 |
|
32 | | - /** |
33 | | - * @return array{ |
34 | | - * timeout: float, |
35 | | - * maxRetries: int, |
36 | | - * initialRetryDelay: float, |
37 | | - * maxRetryDelay: float, |
38 | | - * extraHeaders: list<string>, |
39 | | - * extraQueryParams: list<string>, |
40 | | - * extraBodyParams: list<string>, |
41 | | - * } |
42 | | - */ |
43 | | - public function __serialize(): array |
44 | | - { |
45 | | - return [ |
46 | | - 'timeout' => $this->timeout, |
47 | | - 'maxRetries' => $this->maxRetries, |
48 | | - 'initialRetryDelay' => $this->initialRetryDelay, |
49 | | - 'maxRetryDelay' => $this->maxRetryDelay, |
50 | | - 'extraHeaders' => $this->extraHeaders, |
51 | | - 'extraQueryParams' => $this->extraQueryParams, |
52 | | - 'extraBodyParams' => $this->extraBodyParams, |
53 | | - ]; |
54 | | - } |
| 51 | + /** @var array<string, string|int|list<string|int>|null> $extraHeaders */ |
| 52 | + #[Property] |
| 53 | + public array $extraHeaders = []; |
| 54 | + |
| 55 | + /** @var array<string, mixed> $extraQueryParams */ |
| 56 | + #[Property] |
| 57 | + public array $extraQueryParams = []; |
| 58 | + |
| 59 | + #[Property] |
| 60 | + public mixed $extraBodyParams; |
| 61 | + |
| 62 | + #[Property(optional: true)] |
| 63 | + public ?ClientInterface $transporter; |
| 64 | + |
| 65 | + #[Property(optional: true)] |
| 66 | + public ?UriFactoryInterface $uriFactory; |
| 67 | + |
| 68 | + #[Property(optional: true)] |
| 69 | + public ?StreamFactoryInterface $streamFactory; |
| 70 | + |
| 71 | + #[Property(optional: true)] |
| 72 | + public ?RequestFactoryInterface $requestFactory; |
55 | 73 |
|
56 | 74 | /** |
57 | | - * @param array{ |
58 | | - * timeout?: float|null, |
59 | | - * maxRetries?: int|null, |
60 | | - * initialRetryDelay?: float|null, |
61 | | - * maxRetryDelay?: float|null, |
62 | | - * extraHeaders?: list<string>|null, |
63 | | - * extraQueryParams?: list<string>|null, |
64 | | - * extraBodyParams?: list<string>|null, |
65 | | - * } $data |
| 75 | + * @param array<string, string|int|list<string|int>|null>|null $extraHeaders |
| 76 | + * @param array<string, mixed>|null $extraQueryParams |
| 77 | + * @param mixed|Omittable $extraBodyParams |
66 | 78 | */ |
67 | | - public function __unserialize(array $data): void |
68 | | - { |
69 | | - $this->timeout = $data['timeout'] ?? self::DEFAULT_TIMEOUT; |
70 | | - $this |
71 | | - ->maxRetries = $data['maxRetries'] ?? self::DEFAULT_MAX_RETRIES |
72 | | - ; |
73 | | - $this |
74 | | - ->initialRetryDelay = $data[ |
75 | | - 'initialRetryDelay' |
76 | | - ] ?? self::DEFAULT_INITIAL_RETRYDELAY |
77 | | - ; |
78 | | - $this->maxRetryDelay = $data[ |
79 | | - 'maxRetryDelay' |
80 | | - ] ?? self::DEFAULT_MAX_RETRY_DELAY; |
81 | | - $this->extraHeaders = $data[ |
82 | | - 'extraHeaders' |
83 | | - ] ?? []; |
84 | | - $this->extraQueryParams = $data['extraQueryParams'] ?? []; |
85 | | - $this |
86 | | - ->extraBodyParams = $data['extraBodyParams'] ?? [] |
| 79 | + public function __construct( |
| 80 | + ?float $timeout = null, |
| 81 | + ?int $maxRetries = null, |
| 82 | + ?float $initialRetryDelay = null, |
| 83 | + ?float $maxRetryDelay = null, |
| 84 | + ?array $extraHeaders = null, |
| 85 | + ?array $extraQueryParams = null, |
| 86 | + mixed $extraBodyParams = omit, |
| 87 | + ?ClientInterface $transporter = null, |
| 88 | + ?UriFactoryInterface $uriFactory = null, |
| 89 | + ?StreamFactoryInterface $streamFactory = null, |
| 90 | + ?RequestFactoryInterface $requestFactory = null, |
| 91 | + ) { |
| 92 | + self::introspect(); |
| 93 | + $this->unsetOptionalProperties(); |
| 94 | + |
| 95 | + null !== $timeout && $this->timeout = $timeout; |
| 96 | + null !== $maxRetries && $this->maxRetries = $maxRetries; |
| 97 | + null !== $initialRetryDelay && $this |
| 98 | + ->initialRetryDelay = $initialRetryDelay |
87 | 99 | ; |
| 100 | + null !== $maxRetryDelay && $this->maxRetryDelay = $maxRetryDelay; |
| 101 | + null !== $extraHeaders && $this->extraHeaders = $extraHeaders; |
| 102 | + null !== $extraQueryParams && $this->extraQueryParams = $extraQueryParams; |
| 103 | + omit !== $extraBodyParams && $this->extraBodyParams = $extraBodyParams; |
| 104 | + null !== $transporter && $this->transporter = $transporter; |
| 105 | + null !== $uriFactory && $this->uriFactory = $uriFactory; |
| 106 | + null !== $streamFactory && $this->streamFactory = $streamFactory; |
| 107 | + null !== $requestFactory && $this->requestFactory = $requestFactory; |
88 | 108 | } |
89 | 109 |
|
90 | 110 | /** |
91 | | - * @param RequestOptions|array{ |
92 | | - * timeout?: float|null, |
93 | | - * maxRetries?: int|null, |
94 | | - * initialRetryDelay?: float|null, |
95 | | - * maxRetryDelay?: float|null, |
96 | | - * extraHeaders?: list<string>|null, |
97 | | - * extraQueryParams?: list<string>|null, |
98 | | - * extraBodyParams?: list<string>|null, |
99 | | - * }|null $options |
| 111 | + * @param request_opts|null $options |
100 | 112 | */ |
101 | 113 | public static function parse(RequestOptions|array|null $options): self |
102 | 114 | { |
|
0 commit comments