public static function build(array $args = [])
    {
        $args += [
            'keyFile'           => null,
            'scopes'            => null,
            'authHttpHandler'   => null,
            'enableCaching'     => true,
            'authCache'         => null,
            'authCacheOptions'  => [],
        ];
        $keyFile = $args['keyFile'];
        $authHttpHandler = $args['authHttpHandler'] ?: self::buildHttpHandlerFactory();

        if (is_null($keyFile)) {
            $loader = self::buildApplicationDefaultCredentials(
                $args['scopes'],
                $authHttpHandler
            );
        } else {
            if (is_string($keyFile)) {
                if (!file_exists($keyFile)) {
                    throw new ValidationException("Could not find keyfile: $keyFile");
                }
                $keyFile = json_decode(file_get_contents($keyFile), true);
            }

            $loader = CredentialsLoader::makeCredentials($args['scopes'], $keyFile);
        }

        if ($args['enableCaching']) {
            $authCache = $args['authCache'] ?: new MemoryCacheItemPool();
            $loader = new FetchAuthTokenCache(
                $loader,
                $args['authCacheOptions'],
                $authCache
            );
        }

        return new CredentialsWrapper($loader, $authHttpHandler);
    }
public static function build(array $args = [])
    {
        $args += [
            'keyFile'           => null,
            'scopes'            => null,
            'authHttpHandler'   => null,
            'enableCaching'     => true,
            'authCache'         => null,
            'authCacheOptions'  => [],
        ];
        $keyFile = $args['keyFile'];
        $authHttpHandler = $args['authHttpHandler'] ?: self::buildHttpHandlerFactory();

        if (is_null($keyFile)) {
            $loader = self::buildApplicationDefaultCredentials(
                $args['scopes'],
                $authHttpHandler
            );
        } else {
            if (is_string($keyFile)) {
                if (!file_exists($keyFile)) {
                    throw new ValidationException("Could not find keyfile: $keyFile");
                }
                $keyFile = json_decode(file_get_contents($keyFile), true);
            }

            $loader = CredentialsLoader::makeCredentials($args['scopes'], $keyFile);
        }

        if ($args['enableCaching']) {
            $authCache = $args['authCache'] ?: new MemoryCacheItemPool();
            $loader = new FetchAuthTokenCache(
                $loader,
                $args['authCacheOptions'],
                $authCache
            );
        }

        return new CredentialsWrapper($loader, $authHttpHandler);
    }
public static function build ( array $ args = [ ] ) { $ args += [ 'keyFile' => null , 'scopes' => null , 'authHttpHandler' => null , 'enableCaching' => true , 'authCache' => null , 'authCacheOptions' => [ ] , ] ; $ keyFile = $ args [ 'keyFile' ] ; $ authHttpHandler = $ args [ 'authHttpHandler' ] ? : self :: buildHttpHandlerFactory ( ) ; if ( is_null ( $ keyFile ) ) { $ loader = self :: buildApplicationDefaultCredentials ( $ args [ 'scopes' ] , $ authHttpHandler ) ; } else { if ( is_string ( $ keyFile ) ) { if ( ! file_exists ( $ keyFile ) ) { throw new ValidationException ( "Could not find keyfile: $keyFile" ) ; } $ keyFile = json_decode ( file_get_contents ( $ keyFile ) , true ) ; } $ loader = CredentialsLoader :: makeCredentials ( $ args [ 'scopes' ] , $ keyFile ) ; } if ( $ args [ 'enableCaching' ] ) { $ authCache = $ args [ 'authCache' ] ? : new MemoryCacheItemPool ( ) ; $ loader = new FetchAuthTokenCache ( $ loader , $ args [ 'authCacheOptions' ] , $ authCache ) ; } return new CredentialsWrapper ( $ loader , $ authHttpHandler ) ; }
Factory method to create a CredentialsWrapper from an array of options.

@param array $args {
An array of optional arguments.

@type string|array $keyFile
Credentials to be used. Accepts either a path to a credentials file, or a decoded
credentials file as a PHP array. If this is not specified, application default
credentials will be used.
@type string[] $scopes
A string array of scopes to use when acquiring credentials.
@type callable $authHttpHandler
A handler used to deliver PSR-7 requests specifically
for authentication. Should match a signature of
`function (RequestInterface $request, array $options) : ResponseInterface`.
@type bool $enableCaching
Enable caching of access tokens. Defaults to true.
@type CacheItemPoolInterface $authCache
A cache for storing access tokens. Defaults to a simple in memory implementation.
@type array $authCacheOptions
Cache configuration options.
}
@return CredentialsWrapper
@throws ValidationException
Factory method to create a CredentialsWrapper from an array of options .