| 1 | <?php |
| 2 | |
| 3 | namespace Illuminate\Support\Facades; |
| 4 | |
| 5 | use Illuminate\Http\Client\Factory; |
| 6 | |
| 7 | /** |
| 8 | * @method static \Illuminate\Http\Client\Factory globalMiddleware(callable $middleware) |
| 9 | * @method static \Illuminate\Http\Client\Factory globalRequestMiddleware(callable $middleware) |
| 10 | * @method static \Illuminate\Http\Client\Factory globalResponseMiddleware(callable $middleware) |
| 11 | * @method static \Illuminate\Http\Client\Factory globalOptions(\Closure|array $options) |
| 12 | * @method static \GuzzleHttp\Promise\PromiseInterface response(array|string|null $body = null, int $status = 200, array $headers = []) |
| 13 | * @method static \GuzzleHttp\Psr7\Response psr7Response(array|string|null $body = null, int $status = 200, array $headers = []) |
| 14 | * @method static \Illuminate\Http\Client\RequestException failedRequest(array|string|null $body = null, int $status = 200, array $headers = []) |
| 15 | * @method static \Closure failedConnection(string|null $message = null) |
| 16 | * @method static \Illuminate\Http\Client\ResponseSequence sequence(array $responses = []) |
| 17 | * @method static bool preventingStrayRequests() |
| 18 | * @method static \Illuminate\Http\Client\Factory allowStrayRequests(array|null $only = null) |
| 19 | * @method static \Illuminate\Http\Client\Factory record() |
| 20 | * @method static void recordRequestResponsePair(\Illuminate\Http\Client\Request $request, \Illuminate\Http\Client\Response|null $response) |
| 21 | * @method static void assertSent(callable|\Closure $callback) |
| 22 | * @method static void assertSentInOrder(array $callbacks) |
| 23 | * @method static void assertNotSent(callable|\Closure $callback) |
| 24 | * @method static void assertNothingSent() |
| 25 | * @method static void assertSentCount(int $count) |
| 26 | * @method static void assertSequencesAreEmpty() |
| 27 | * @method static \Illuminate\Support\Collection recorded(\Closure|callable $callback = null) |
| 28 | * @method static \Illuminate\Http\Client\PendingRequest createPendingRequest() |
| 29 | * @method static \Illuminate\Contracts\Events\Dispatcher|null getDispatcher() |
| 30 | * @method static array getGlobalMiddleware() |
| 31 | * @method static void macro(string $name, object|callable $macro) |
| 32 | * @method static void mixin(object $mixin, bool $replace = true) |
| 33 | * @method static bool hasMacro(string $name) |
| 34 | * @method static void flushMacros() |
| 35 | * @method static mixed macroCall(string $method, array $parameters) |
| 36 | * @method static \Illuminate\Http\Client\PendingRequest baseUrl(string $url) |
| 37 | * @method static \Illuminate\Http\Client\PendingRequest withBody(\Psr\Http\Message\StreamInterface|string $content, string $contentType = 'application/json') |
| 38 | * @method static \Illuminate\Http\Client\PendingRequest asJson() |
| 39 | * @method static \Illuminate\Http\Client\PendingRequest asForm() |
| 40 | * @method static \Illuminate\Http\Client\PendingRequest attach(string|array $name, string|resource $contents = '', string|null $filename = null, array $headers = []) |
| 41 | * @method static \Illuminate\Http\Client\PendingRequest asMultipart() |
| 42 | * @method static \Illuminate\Http\Client\PendingRequest bodyFormat(string $format) |
| 43 | * @method static \Illuminate\Http\Client\PendingRequest withQueryParameters(array $parameters) |
| 44 | * @method static \Illuminate\Http\Client\PendingRequest contentType(string $contentType) |
| 45 | * @method static \Illuminate\Http\Client\PendingRequest acceptJson() |
| 46 | * @method static \Illuminate\Http\Client\PendingRequest accept(string $contentType) |
| 47 | * @method static \Illuminate\Http\Client\PendingRequest withHeaders(array $headers) |
| 48 | * @method static \Illuminate\Http\Client\PendingRequest withHeader(string $name, mixed $value) |
| 49 | * @method static \Illuminate\Http\Client\PendingRequest replaceHeaders(array $headers) |
| 50 | * @method static \Illuminate\Http\Client\PendingRequest withBasicAuth(string $username, string $password) |
| 51 | * @method static \Illuminate\Http\Client\PendingRequest withDigestAuth(string $username, string $password) |
| 52 | * @method static \Illuminate\Http\Client\PendingRequest withNtlmAuth(string $username, string $password) |
| 53 | * @method static \Illuminate\Http\Client\PendingRequest withToken(string $token, string $type = 'Bearer') |
| 54 | * @method static \Illuminate\Http\Client\PendingRequest withUserAgent(string|bool $userAgent) |
| 55 | * @method static \Illuminate\Http\Client\PendingRequest withUrlParameters(array $parameters = []) |
| 56 | * @method static \Illuminate\Http\Client\PendingRequest withCookies(array $cookies, string $domain) |
| 57 | * @method static \Illuminate\Http\Client\PendingRequest maxRedirects(int $max) |
| 58 | * @method static \Illuminate\Http\Client\PendingRequest withoutRedirecting() |
| 59 | * @method static \Illuminate\Http\Client\PendingRequest withoutVerifying() |
| 60 | * @method static \Illuminate\Http\Client\PendingRequest sink(string|resource $to) |
| 61 | * @method static \Illuminate\Http\Client\PendingRequest timeout(int|float $seconds) |
| 62 | * @method static \Illuminate\Http\Client\PendingRequest connectTimeout(int|float $seconds) |
| 63 | * @method static \Illuminate\Http\Client\PendingRequest retry(array|int $times, \Closure|int $sleepMilliseconds = 0, callable|null $when = null, bool $throw = true) |
| 64 | * @method static \Illuminate\Http\Client\PendingRequest withOptions(array $options) |
| 65 | * @method static \Illuminate\Http\Client\PendingRequest withMiddleware(callable $middleware) |
| 66 | * @method static \Illuminate\Http\Client\PendingRequest withRequestMiddleware(callable $middleware) |
| 67 | * @method static \Illuminate\Http\Client\PendingRequest withResponseMiddleware(callable $middleware) |
| 68 | * @method static \Illuminate\Http\Client\PendingRequest withAttributes(array $attributes) |
| 69 | * @method static \Illuminate\Http\Client\PendingRequest beforeSending(callable $callback) |
| 70 | * @method static \Illuminate\Http\Client\PendingRequest afterResponse(callable|null $callback) |
| 71 | * @method static \Illuminate\Http\Client\PendingRequest throw(callable|null $callback = null) |
| 72 | * @method static \Illuminate\Http\Client\PendingRequest throwIf(callable|bool $condition) |
| 73 | * @method static \Illuminate\Http\Client\PendingRequest throwUnless(callable|bool $condition) |
| 74 | * @method static \Illuminate\Http\Client\PendingRequest dump() |
| 75 | * @method static \Illuminate\Http\Client\PendingRequest dd() |
| 76 | * @method static \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface get(string $url, array|string|null $query = null) |
| 77 | * @method static \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface head(string $url, array|string|null $query = null) |
| 78 | * @method static \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface post(string $url, array|\JsonSerializable|\Illuminate\Contracts\Support\Arrayable $data = []) |
| 79 | * @method static \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface patch(string $url, array|\JsonSerializable|\Illuminate\Contracts\Support\Arrayable $data = []) |
| 80 | * @method static \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface put(string $url, array|\JsonSerializable|\Illuminate\Contracts\Support\Arrayable $data = []) |
| 81 | * @method static \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface delete(string $url, array|\JsonSerializable|\Illuminate\Contracts\Support\Arrayable $data = []) |
| 82 | * @method static array pool(callable $callback, int|null $concurrency = null) |
| 83 | * @method static \Illuminate\Http\Client\Batch batch(callable $callback) |
| 84 | * @method static \Illuminate\Http\Client\Response|\Illuminate\Http\Client\Promises\LazyPromise send(string $method, string $url, array $options = []) |
| 85 | * @method static \GuzzleHttp\Client buildClient() |
| 86 | * @method static \GuzzleHttp\Client createClient(\GuzzleHttp\HandlerStack $handlerStack) |
| 87 | * @method static \GuzzleHttp\HandlerStack buildHandlerStack() |
| 88 | * @method static \GuzzleHttp\HandlerStack pushHandlers(\GuzzleHttp\HandlerStack $handlerStack) |
| 89 | * @method static \Closure buildBeforeSendingHandler() |
| 90 | * @method static \Closure buildRecorderHandler() |
| 91 | * @method static \Closure buildStubHandler() |
| 92 | * @method static \Psr\Http\Message\RequestInterface runBeforeSendingCallbacks(\Psr\Http\Message\RequestInterface $request, array $options) |
| 93 | * @method static array mergeOptions(array ...$options) |
| 94 | * @method static \Illuminate\Http\Client\PendingRequest stub(callable $callback) |
| 95 | * @method static bool isAllowedRequestUrl(string $url) |
| 96 | * @method static \Illuminate\Http\Client\PendingRequest async(bool $async = true) |
| 97 | * @method static \GuzzleHttp\Promise\PromiseInterface|null getPromise() |
| 98 | * @method static \Illuminate\Http\Client\PendingRequest truncateExceptionsAt(int $length) |
| 99 | * @method static \Illuminate\Http\Client\PendingRequest dontTruncateExceptions() |
| 100 | * @method static \Illuminate\Http\Client\PendingRequest setClient(\GuzzleHttp\Client $client) |
| 101 | * @method static \Illuminate\Http\Client\PendingRequest setHandler(callable $handler) |
| 102 | * @method static array getOptions() |
| 103 | * @method static \Illuminate\Http\Client\PendingRequest|mixed when(\Closure|mixed|null $value = null, callable|null $callback = null, callable|null $default = null) |
| 104 | * @method static \Illuminate\Http\Client\PendingRequest|mixed unless(\Closure|mixed|null $value = null, callable|null $callback = null, callable|null $default = null) |
| 105 | * |
| 106 | * @see \Illuminate\Http\Client\Factory |
| 107 | */ |
| 108 | class Http extends Facade |
| 109 | { |
| 110 | /** |
| 111 | * Get the registered name of the component. |
| 112 | * |
| 113 | * @return string |
| 114 | */ |
| 115 | protected static function getFacadeAccessor() |
| 116 | { |
| 117 | return Factory::class; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Register a stub callable that will intercept requests and be able to return stub responses. |
| 122 | * |
| 123 | * @param \Closure|array|null $callback |
| 124 | * @return \Illuminate\Http\Client\Factory |
| 125 | */ |
| 126 | public static function fake($callback = null) |
| 127 | { |
| 128 | return tap(static::getFacadeRoot(), function ($fake) use ($callback) { |
| 129 | static::swap($fake->fake($callback)); |
| 130 | }); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Register a response sequence for the given URL pattern. |
| 135 | * |
| 136 | * @param string $urlPattern |
| 137 | * @return \Illuminate\Http\Client\ResponseSequence |
| 138 | */ |
| 139 | public static function fakeSequence(string $urlPattern = '*') |
| 140 | { |
| 141 | $fake = tap(static::getFacadeRoot(), function ($fake) { |
| 142 | static::swap($fake); |
| 143 | }); |
| 144 | |
| 145 | return $fake->fakeSequence($urlPattern); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Indicate that an exception should be thrown if any request is not faked. |
| 150 | * |
| 151 | * @param bool $prevent |
| 152 | * @return \Illuminate\Http\Client\Factory |
| 153 | */ |
| 154 | public static function preventStrayRequests($prevent = true) |
| 155 | { |
| 156 | return tap(static::getFacadeRoot(), function ($fake) use ($prevent) { |
| 157 | static::swap($fake->preventStrayRequests($prevent)); |
| 158 | }); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Stub the given URL using the given callback. |
| 163 | * |
| 164 | * @param string $url |
| 165 | * @param \Illuminate\Http\Client\Response|\GuzzleHttp\Promise\PromiseInterface|callable $callback |
| 166 | * @return \Illuminate\Http\Client\Factory |
| 167 | */ |
| 168 | public static function stubUrl($url, $callback) |
| 169 | { |
| 170 | return tap(static::getFacadeRoot(), function ($fake) use ($url, $callback) { |
| 171 | static::swap($fake->stubUrl($url, $callback)); |
| 172 | }); |
| 173 | } |
| 174 | } |