GapicClientTrait
trait GapicClientTrait (View source)
internal |
Common functions used to work with various clients.
Traits
Provides basic array helper methods.
Provides helper methods for gRPC support.
Methods
Add a middleware to the call stack by providing a callable which will be invoked at the start of each call, and will return an instance of {MiddlewareInterface} when invoked.
Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.
Details
static array
validate(array $arr, array $requiredKeys)
No description
static array
validateNotNull(array $arr, array $requiredKeys)
No description
void
addMiddleware(callable $middlewareCallable)
Add a middleware to the call stack by providing a callable which will be invoked at the start of each call, and will return an instance of {MiddlewareInterface} when invoked.
The callable must have the following method signature:
callable(MiddlewareInterface): MiddlewareInterface
An implementation may look something like this:
$client->addMiddleware(function (MiddlewareInterface $handler) {
return new class ($handler) implements MiddlewareInterface {
public function __construct(private MiddlewareInterface $handler) {
}
public function __invoke(Call $call, array $options) {
// modify call and options (pre-request)
$response = ($this->handler)($call, $options);
// modify the response (post-request)
return $response;
}
};
});
close()
Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.