WordPress\AiClient\Providers

ProviderRegistry::setRequestAuthenticationForProviderprivateWP 0.1.0

Sets the request authentication for a specific provider, hooking up its class instances.

Метод класса: ProviderRegistry{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->setRequestAuthenticationForProvider( $className, $requestAuthentication ): void;
$className(class-string) (обязательный)
The provider class name.
$requestAuthentication(RequestAuthenticationInterface) (обязательный)
The authentication instance.

Список изменений

С версии 0.1.0 Введена.

Код ProviderRegistry::setRequestAuthenticationForProvider() WP 7.0

private function setRequestAuthenticationForProvider(string $className, RequestAuthenticationInterface $requestAuthentication): void
{
    $authenticationMethod = $className::metadata()->getAuthenticationMethod();
    if ($authenticationMethod === null) {
        throw new InvalidArgumentException(sprintf('Provider %s does not expect any authentication, but got %s.', $className, get_class($requestAuthentication)));
    }
    $expectedClass = $authenticationMethod->getImplementationClass();
    if (!$requestAuthentication instanceof $expectedClass) {
        throw new InvalidArgumentException(sprintf('Provider %s expects authentication of type %s, but got %s.', $className, $expectedClass, get_class($requestAuthentication)));
    }
    $availability = $className::availability();
    if ($availability instanceof WithRequestAuthenticationInterface) {
        $availability->setRequestAuthentication($requestAuthentication);
    }
    $modelMetadataDirectory = $className::modelMetadataDirectory();
    if ($modelMetadataDirectory instanceof WithRequestAuthenticationInterface) {
        $modelMetadataDirectory->setRequestAuthentication($requestAuthentication);
    }
    if (is_subclass_of($className, ProviderWithOperationsHandlerInterface::class)) {
        $operationsHandler = $className::operationsHandler();
        if ($operationsHandler instanceof WithRequestAuthenticationInterface) {
            $operationsHandler->setRequestAuthentication($requestAuthentication);
        }
    }
}