6
6
use Rcalicdan \FiberAsync \Http \Request ;
7
7
use Rcalicdan \FiberAsync \Http \Response ;
8
8
use Rcalicdan \FiberAsync \Http \StreamingResponse ;
9
+ use Rcalicdan \FiberAsync \Promise \Interfaces \CancellablePromiseInterface ;
9
10
use Rcalicdan \FiberAsync \Promise \Interfaces \PromiseInterface ;
10
11
11
12
/**
16
17
* underlying handler and event loop management for a more convenient API.
17
18
*
18
19
* @method static Request request() Creates a new fluent request builder.
19
- * @method static PromiseInterface<Response> get(string $url, array $query = []) Performs a GET request.
20
- * @method static PromiseInterface<Response> post(string $url, array $data = []) Performs a POST request.
21
- * @method static PromiseInterface<Response> put(string $url, array $data = []) Performs a PUT request.
20
+ * @method static PromiseInterface<Response> get(string $url, array<string, mixed> $query = []) Performs a GET request.
21
+ * @method static PromiseInterface<Response> post(string $url, array<string, mixed> $data = []) Performs a POST request.
22
+ * @method static PromiseInterface<Response> put(string $url, array<string, mixed> $data = []) Performs a PUT request.
22
23
* @method static PromiseInterface<Response> delete(string $url) Performs a DELETE request.
23
- * @method static PromiseInterface<Response> fetch(string $url, array $options = []) A flexible, fetch-like request method.
24
- * @method static PromiseInterface<StreamingResponse> stream(string $url, array $options = [], ?callable $onChunk = null) Streams a response body.
25
- * @method static PromiseInterface <array{file: string, status: int|null , headers: array}> download(string $url, string $destination, array $options = []) Downloads a file.
24
+ * @method static PromiseInterface<Response> fetch(string $url, array<int|string, mixed> $options = []) A flexible, fetch-like request method.
25
+ * @method static PromiseInterface<StreamingResponse> stream(string $url, array<int|string, mixed> $options = [], ?callable $onChunk = null) Streams a response body.
26
+ * @method static CancellablePromiseInterface <array{file: string, status: int, headers: array<mixed> }> download(string $url, string $destination, array<int|string, mixed> $options = []) Downloads a file.
26
27
*/
27
28
class AsyncHttp
28
29
{
@@ -55,7 +56,7 @@ public static function request(): Request
55
56
* Performs a quick, asynchronous GET request.
56
57
*
57
58
* @param string $url The target URL.
58
- * @param array $query Optional query parameters.
59
+ * @param array<string, mixed> $query Optional query parameters.
59
60
* @return PromiseInterface<Response> A promise that resolves with a Response object.
60
61
*/
61
62
public static function get (string $ url , array $ query = []): PromiseInterface
@@ -67,7 +68,7 @@ public static function get(string $url, array $query = []): PromiseInterface
67
68
* Performs a quick, asynchronous POST request with a JSON payload.
68
69
*
69
70
* @param string $url The target URL.
70
- * @param array $data Data to be JSON-encoded.
71
+ * @param array<string, mixed> $data Data to be JSON-encoded.
71
72
* @return PromiseInterface<Response> A promise that resolves with a Response object.
72
73
*/
73
74
public static function post (string $ url , array $ data = []): PromiseInterface
@@ -79,7 +80,7 @@ public static function post(string $url, array $data = []): PromiseInterface
79
80
* Performs a quick, asynchronous PUT request.
80
81
*
81
82
* @param string $url The target URL.
82
- * @param array $data Data to be JSON-encoded.
83
+ * @param array<string, mixed> $data Data to be JSON-encoded.
83
84
* @return PromiseInterface<Response> A promise that resolves with a Response object.
84
85
*/
85
86
public static function put (string $ url , array $ data = []): PromiseInterface
@@ -102,7 +103,7 @@ public static function delete(string $url): PromiseInterface
102
103
* A flexible, fetch-like method for making HTTP requests.
103
104
*
104
105
* @param string $url The target URL.
105
- * @param array $options Associative array of request options (method, headers, body, etc.).
106
+ * @param array<int|string, mixed> $options Associative array of request options (method, headers, body, etc.).
106
107
* @return PromiseInterface<Response> A promise that resolves with a Response object.
107
108
*/
108
109
public static function fetch (string $ url , array $ options = []): PromiseInterface
@@ -114,11 +115,11 @@ public static function fetch(string $url, array $options = []): PromiseInterface
114
115
* Streams an HTTP response, processing it in chunks.
115
116
*
116
117
* @param string $url The URL to stream from.
117
- * @param array $options Advanced cURL or request options.
118
+ * @param array<int|string, mixed> $options Advanced cURL or request options.
118
119
* @param callable|null $onChunk Optional callback for each data chunk.
119
- * @return PromiseInterface <StreamingResponse> A promise resolving with a StreamingResponse object.
120
+ * @return CancellablePromiseInterface <StreamingResponse> A promise resolving with a StreamingResponse object.
120
121
*/
121
- public static function stream (string $ url , array $ options = [], ?callable $ onChunk = null ): PromiseInterface
122
+ public static function stream (string $ url , array $ options = [], ?callable $ onChunk = null ): CancellablePromiseInterface
122
123
{
123
124
return self ::getInstance ()->stream ($ url , $ options , $ onChunk );
124
125
}
@@ -128,10 +129,10 @@ public static function stream(string $url, array $options = [], ?callable $onChu
128
129
*
129
130
* @param string $url The URL of the file to download.
130
131
* @param string $destination The local path to save the file.
131
- * @param array $options Advanced cURL or request options.
132
- * @return PromiseInterface <array{file: string, status: int|null , headers: array}> A promise resolving with download metadata.
132
+ * @param array<int|string, mixed> $options Advanced cURL or request options.
133
+ * @return CancellablePromiseInterface <array{file: string, status: int, headers: array<mixed> }> A promise resolving with download metadata.
133
134
*/
134
- public static function download (string $ url , string $ destination , array $ options = []): PromiseInterface
135
+ public static function download (string $ url , string $ destination , array $ options = []): CancellablePromiseInterface
135
136
{
136
137
return self ::getInstance ()->download ($ url , $ destination , $ options );
137
138
}
@@ -158,11 +159,11 @@ public static function setInstance(HttpHandler $handler): void
158
159
* Magic method to handle dynamic static calls and proxy them to the handler instance.
159
160
*
160
161
* @param string $method The method name.
161
- * @param array $arguments The arguments to pass to the method.
162
+ * @param array<mixed> $arguments The arguments to pass to the method.
162
163
* @return mixed The result of the proxied method call.
163
164
*/
164
165
public static function __callStatic (string $ method , array $ arguments )
165
166
{
166
167
return self ::getInstance ()->{$ method }(...$ arguments );
167
168
}
168
- }
169
+ }
0 commit comments