Google Cloud PHP shared dependency, providing functionality useful to all components. Client - Class ServiceBuilder (1.51.2)

Reference documentation and code samples for the Google Cloud PHP shared dependency, providing functionality useful to all components. Client class ServiceBuilder.

Google Cloud Platform is a set of modular cloud-based services that allow you to create anything from simple websites to complex applications.

This API aims to expose access to these services in a way that is intuitive and easy to use for PHP enthusiasts. The ServiceBuilder instance exposes factory methods which grant access to the various services contained within the API.

Configuration is simple. Pass in an array of configuration options to the constructor up front which can be shared between clients or specify the options for the specific services you wish to access, e.g. Datastore, or Storage.

Please note that unless otherwise noted the examples below take advantage of Application Default Credentials.

Namespace

Google \ Cloud \ Core

Methods

__construct

Pass in an array of configuration options which will be shared between clients.

Example:

use Google\Cloud\Core\ServiceBuilder;

$cloud = new ServiceBuilder([
    'projectId' => 'myAwesomeProject'
]);
Parameters
NameDescription
config array

Configuration options.

↳ projectId string

The project ID from the Google Developer's Console.

↳ authCache CacheItemPoolInterface

A cache for storing access tokens. Defaults to a simple in memory implementation.

↳ authCacheOptions array

Cache configuration options.

↳ authHttpHandler callable

A handler used to deliver Psr7 requests specifically for authentication.

↳ httpHandler callable

A handler used to deliver Psr7 requests. Only valid for requests sent over REST.

↳ keyFile array

The contents of the service account credentials .json file retrieved from the Google Developer's Console. Ex: json_decode(file_get_contents($path), true).

↳ keyFilePath string

The full path to your service account credentials .json file retrieved from the Google Developers Console.

↳ retries int

Number of retries for a failed request. Defaults to 3.

↳ scopes array

Scopes to be used for the request.

bigQuery

Google Cloud BigQuery allows you to create, manage, share and query data. Find more information at the Google Cloud BigQuery Docs.

Example:

$bigQuery = $cloud->bigQuery();
Parameters
NameDescription
config array

Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the other available options.

↳ returnInt64AsObject bool

If true, 64 bit integers will be returned as a Google\Cloud\Core\Google\Cloud\Core\Int64 object for 32 bit platform compatibility. Defaults to false.

↳ location string

If provided, determines the default geographic location used when creating datasets and managing jobs. Please note: This is only required for jobs started outside of the US and EU regions. Also, if location metadata has already been fetched over the network it will take precedent over this setting.

Returns
TypeDescription
Google\Cloud\BigQuery\BigQueryClient

datastore

Google Cloud Datastore is a highly-scalable NoSQL database for your applications. Find more information at the Google Cloud Datastore docs.

Example:

$datastore = $cloud->datastore();
Parameters
NameDescription
config array

Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the other available options.

↳ returnInt64AsObject bool

If true, 64 bit integers will be returned as a Google\Cloud\Core\Google\Cloud\Core\Int64 object for 32 bit platform compatibility. Defaults to false

Returns
TypeDescription
Google\Cloud\Datastore\DatastoreClient

firestore

Cloud Firestore is a flexible, scalable, realtime database for mobile, web, and server development. Find more information at the Google Cloud firestore docs.

Example:

$firestore = $cloud->firestore();
Parameters
NameDescription
config array

Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the other available options.

↳ returnInt64AsObject bool

If true, 64 bit integers will be returned as a Google\Cloud\Core\Google\Cloud\Core\Int64 object for 32 bit platform compatibility. Defaults to false

Returns
TypeDescription
Google\Cloud\Firestore\FirestoreClient

logging

Google Stackdriver Logging allows you to store, search, analyze, monitor, and alert on log data and events from Google Cloud Platform and Amazon Web Services. Find more information at the Google Stackdriver Logging docs.

Example:

$logging = $cloud->logging();
Parameter
NameDescription
config array

[optional] Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the available options.

Returns
TypeDescription
Google\Cloud\Logging\LoggingClient

language

Google Cloud Natural Language provides natural language understanding technologies to developers, including sentiment analysis, entity recognition, and syntax analysis. Currently only English, Spanish, and Japanese textual context are supported. Find more information at the Google Cloud Natural Language docs.

Example:

$language = $cloud->language();
Parameter
NameDescription
config array

[optional] Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the available options.

Returns
TypeDescription
Google\Cloud\Language\LanguageClient

pubsub

Google Cloud Pub/Sub allows you to send and receive messages between independent applications. Find more information at the Google Cloud Pub/Sub docs.

Example:

$pubsub = $cloud->pubsub();
Parameters
NameDescription
config array

Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the other available options.

↳ transport string

The transport type used for requests. May be either grpc or rest. Defaults to grpc if gRPC support is detected on the system

Returns
TypeDescription
Google\Cloud\PubSub\PubSubClient

spanner

Google Cloud Spanner is a highly scalable, transactional, managed, NewSQL database service. Find more information at Google Cloud Spanner API docs.

Example:

$spanner = $cloud->spanner();
Parameters
NameDescription
config array

Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the other available options.

↳ returnInt64AsObject bool

If true, 64 bit integers will be returned as a Google\Cloud\Core\Google\Cloud\Core\Int64 object for 32 bit platform compatibility. Defaults to false.

Returns
TypeDescription
Google\Cloud\Spanner\SpannerClient

speech

Google Cloud Speech enables easy integration of Google speech recognition technologies into developer applications. Send audio and receive a text transcription from the Cloud Speech API service. Find more information at the Google Cloud Speech API docs.

Example:

$speech = $cloud->speech([
    'languageCode' => 'en-US'
]);
Parameters
NameDescription
config array

Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the other available options.

↳ languageCode string

The language of the content to be recognized. Only BCP-47 (e.g., "en-US", "es-ES") language codes are accepted. See Language Support for a list of the currently supported language codes

Returns
TypeDescription
Google\Cloud\Speech\SpeechClient

storage

Google Cloud Storage allows you to store and retrieve data on Google's infrastructure. Find more information at the Google Cloud Storage API docs.

Example:

$storage = $cloud->storage();
Parameter
NameDescription
config array

[optional] Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the available options.

Returns
TypeDescription
Google\Cloud\Storage\StorageClient

trace

Google Stackdriver Trace allows you to collect latency data from your applications and display it in the Google Cloud Platform Console. Find more information at Stackdriver Trace API docs.

Example:

$trace = $cloud->trace();
Parameter
NameDescription
config array

[optional] Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the available options.

Returns
TypeDescription
Google\Cloud\Trace\TraceClient

vision

Google Cloud Vision allows you to understand the content of an image, classify images into categories, detect text, objects, faces and more.

Find more information at the Google Cloud Vision docs.

Example:

$vision = $cloud->vision();
Parameter
NameDescription
config array

[optional] Configuration options. See Google\Cloud\Core\Google\Cloud\Core\ServiceBuilder::__construct() for the available options.

Returns
TypeDescription
Google\Cloud\Vision\VisionClient

translate

Google Cloud Translation provides the ability to dynamically translate text between thousands of language pairs and lets websites and programs integrate with translation service programmatically.

The Google Cloud Translation API is available as a paid service. See the Pricing and FAQ pages for details. Find more information at the the Google Cloud Translation docs.

Please note that while the Google Cloud Translation API supports authentication via service account and application default credentials like other Cloud Platform APIs, it also supports authentication via a public API access key. If you wish to authenticate using an API key, follow the before you begin instructions to learn how to generate a key.

Example:

use Google\Cloud\Core\ServiceBuilder;

$builder = new ServiceBuilder([
    'key' => 'YOUR_KEY'
]);

$translate = $builder->translate();
Parameters
NameDescription
config array

Configuration options.

↳ key string

A public API access key.

↳ target string

The target language to assign to the client. Defaults to en (English).

↳ httpHandler callable

A handler used to deliver Psr7 requests. Only valid for requests sent over REST.

↳ retries int

Number of retries for a failed request. Defaults to 3.

Returns
TypeDescription
Google\Cloud\Translate\V2\TranslateClient