| @@ 92-109 (lines=18) @@ | ||
| 89 | * |
|
| 90 | * @return HttpClient |
|
| 91 | */ |
|
| 92 | private static function buildHttpClient04( |
|
| 93 | LoopInterface $loop, |
|
| 94 | $dns = null |
|
| 95 | ) { |
|
| 96 | // create dns resolver if one isn't provided |
|
| 97 | if (null === $dns) { |
|
| 98 | $dns = static::buildDnsResolver($loop); |
|
| 99 | } |
|
| 100 | ||
| 101 | // validate connector instance for proper error reporting |
|
| 102 | if (!$dns instanceof DnsResolver) { |
|
| 103 | throw new \InvalidArgumentException('$connector must be an instance of DnsResolver'); |
|
| 104 | } |
|
| 105 | ||
| 106 | $factory = new HttpClientFactory(); |
|
| 107 | ||
| 108 | return $factory->create($loop, $dns); |
|
| 109 | } |
|
| 110 | ||
| 111 | /** |
|
| 112 | * Builds a React Http client v0.5 style. |
|
| @@ 119-136 (lines=18) @@ | ||
| 116 | * |
|
| 117 | * @return HttpClient |
|
| 118 | */ |
|
| 119 | private static function buildHttpClient05( |
|
| 120 | LoopInterface $loop, |
|
| 121 | $connector = null |
|
| 122 | ) { |
|
| 123 | // build a connector with given DnsResolver if provided (old deprecated behavior) |
|
| 124 | if ($connector instanceof DnsResolver) { |
|
| 125 | $connector = static::buildConnector($loop, $connector); |
|
| 126 | } |
|
| 127 | ||
| 128 | // validate connector instance for proper error reporting |
|
| 129 | if (null !== $connector && !$connector instanceof ConnectorInterface) { |
|
| 130 | throw new \InvalidArgumentException( |
|
| 131 | '$connector must be an instance of DnsResolver or ConnectorInterface' |
|
| 132 | ); |
|
| 133 | } |
|
| 134 | ||
| 135 | return new HttpClient($loop, $connector); |
|
| 136 | } |
|
| 137 | } |
|
| 138 | ||