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