WordPress\AiClient\Providers\Http
HttpTransporter::isGuzzleClient
Determines if the underlying client matches the Guzzle client shape.
Method of the class: HttpTransporter{}
No Hooks.
Returns
true|false. True when the client exposes Guzzle's send signature.
Usage
// private - for code of main (parent) class only $result = $this->isGuzzleClient( $client ): bool;
- $client(ClientInterface) (required)
- The HTTP client instance.
Changelog
| Since 0.2.0 | Introduced. |
HttpTransporter::isGuzzleClient() HttpTransporter::isGuzzleClient code WP 7.0
private function isGuzzleClient(ClientInterface $client): bool
{
$reflection = new \ReflectionObject($client);
if (!is_callable([$client, 'send'])) {
return \false;
}
if (!$reflection->hasMethod('send')) {
return \false;
}
$method = $reflection->getMethod('send');
if (!$method->isPublic() || $method->isStatic()) {
return \false;
}
$parameters = $method->getParameters();
if (count($parameters) < 2) {
return \false;
}
$firstParameter = $parameters[0]->getType();
if (!$firstParameter instanceof \ReflectionNamedType || $firstParameter->isBuiltin()) {
return \false;
}
if (!is_a($firstParameter->getName(), RequestInterface::class, \true)) {
return \false;
}
$secondParameter = $parameters[1];
$secondType = $secondParameter->getType();
if (!$secondType instanceof \ReflectionNamedType || $secondType->getName() !== 'array') {
return \false;
}
return \true;
}