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.
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 | |
---|---|
Name | Description |
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: |
↳ 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 |
↳ 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 | |
---|---|
Name | Description |
config |
array
Configuration options. See {@see} for the other available options. |
↳ returnInt64AsObject |
bool
If true, 64 bit integers will be returned as a {@see} 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 | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
Configuration options. See {@see} for the other available options. |
↳ returnInt64AsObject |
bool
If true, 64 bit integers will be returned as a {@see} object for 32 bit platform compatibility. Defaults to false |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
Configuration options. See {@see} for the other available options. |
↳ returnInt64AsObject |
bool
If true, 64 bit integers will be returned as a {@see} object for 32 bit platform compatibility. Defaults to false |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
[optional] Configuration options. See {@see} for the available options. |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
[optional] Configuration options. See {@see} for the available options. |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
Configuration options. See {@see} for the other available options. |
↳ transport |
string
The transport type used for requests. May be either |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
Configuration options. See {@see} for the other available options. |
↳ returnInt64AsObject |
bool
If true, 64 bit integers will be returned as a {@see} object for 32 bit platform compatibility. Defaults to false. |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
Configuration options. See {@see} for the other available options. |
↳ languageCode |
string
The language of the content to be recognized. Only BCP-47 (e.g., |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
[optional] Configuration options. See {@see} for the available options. |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
[optional] Configuration options. See {@see} for the available options. |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
[optional] Configuration options. See {@see} for the available options. |
Returns | |
---|---|
Type | Description |
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 | |
---|---|
Name | Description |
config |
array
Configuration options. |
↳ key |
string
A public API access key. |
↳ target |
string
The target language to assign to the client. Defaults to |
↳ 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 |
Returns | |
---|---|
Type | Description |
Google\Cloud\Translate\V2\TranslateClient |