trait GapicClientTrait (View source)

internal  
 

Common functions used to work with various clients.

Traits

Common functions used to work with various clients.

Provides helper methods for gRPC support.

Provides basic array helper methods.

Methods

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.

close()

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

Parameters

array $arr

Associative array

array $requiredKeys

List of keys to check for in $arr

Return Value

array

Returns $arr for fluent use

static array validateNotNull(array $arr, array $requiredKeys)

No description

Parameters

array $arr

Associative array

array $requiredKeys

List of keys to check for in $arr

Return Value

array

Returns $arr for fluent use

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

Parameters

callable $middlewareCallable

A callable which returns an instance of {\Google\ApiCore\MiddlewareInterface} when invoked with a MiddlewareInterface instance as its first argument.

Return Value

void

close()

Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately cancelled.