HttpTransporter::isGuzzleClient( WordPressAiClientDependenciesPsrHttpClientClientInterface $client ): bool

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Determines if the underlying client matches the Guzzle client shape.

Parameters

$clientWordPressAiClientDependenciesPsrHttpClientClientInterfacerequired
The HTTP client instance.

Return

bool True when the client exposes Guzzle’s send signature.

Source

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;
}

Changelog

VersionDescription
0.2.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.