1 | <?php |
||
18 | class Client implements HttpClient, HttpAsyncClient |
||
19 | { |
||
20 | /** |
||
21 | * @var ClientInterface |
||
22 | */ |
||
23 | private $client; |
||
24 | |||
25 | /** |
||
26 | * @param ClientInterface|null $client |
||
27 | */ |
||
28 | 324 | public function __construct(ClientInterface $client = null) |
|
29 | { |
||
30 | 324 | if (!$client) { |
|
31 | $client = static::buildClient(); |
||
32 | } |
||
33 | |||
34 | 324 | $this->client = $client; |
|
35 | 324 | } |
|
36 | |||
37 | /** |
||
38 | * Factory method to create the guzzle 6 adapter with custom configuration for guzzle. |
||
39 | * |
||
40 | * @param array $config Configuration to create guzzle with. |
||
41 | * |
||
42 | * @return Client |
||
43 | */ |
||
44 | public static function createWithConfig(array $config) |
||
45 | { |
||
46 | return new self(static::buildClient($config)); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | 159 | public function sendRequest(RequestInterface $request) |
|
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 324 | public function sendAsyncRequest(RequestInterface $request) |
|
68 | |||
69 | /** |
||
70 | * Build the guzzle client instance. |
||
71 | * |
||
72 | * @param array $config Additional configuration |
||
73 | * |
||
74 | * @return GuzzleClient |
||
75 | */ |
||
76 | private static function buildClient(array $config) |
||
84 | } |
||
85 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: