Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the Datastore emulator #181

Merged
merged 1 commit into from
Oct 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Datastore/Connection/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ class Rest implements ConnectionInterface
*/
public function __construct(array $config = [])
{
$emulatorHost = getenv('DATASTORE_EMULATOR_HOST');

$baseUri = $this->getEmulatorBaseUri(self::BASE_URI, $emulatorHost);

$this->setRequestWrapper(new RequestWrapper($config));
$this->setRequestBuilder(new RequestBuilder(
__DIR__ . '/ServiceDefinition/datastore-v1.json',
self::BASE_URI
$baseUri
));
}

Expand Down
18 changes: 18 additions & 0 deletions src/Datastore/DatastoreClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
* through use of data partitions. A partition ID can be supplied when creating an instance of Cloud Datastore, and will
* be used in all operations executed in that instance.
*
* To enable the
* [Google Cloud Datastore Emulator](https://cloud.google.com/datastore/docs/tools/datastore-emulator),
* set the
* [`PUBSUB_EMULATOR_HOST`](https://cloud.google.com/datastore/docs/tools/datastore-emulator#setting_environment_variables)
* environment variable.
*
* Example:
* ```
* use Google\Cloud\ServiceBuilder;
Expand Down Expand Up @@ -62,6 +68,18 @@
* 'namespaceId' => 'my-application-namespace'
* ]);
* ```
*
* ```
* // Using the Datastore Emulator
* use Google\Cloud\ServiceBuilder;
*
* // Be sure to use the port specified when starting the emulator.
* // `8900` is used as an example only.
* putenv('DATASTORE_EMULATOR_HOST=http://localhost:8900');
*
* $cloud = new ServiceBuilder();
* $datastore = $cloud->datastore();
* ```
*/
class DatastoreClient
{
Expand Down
17 changes: 15 additions & 2 deletions src/PubSub/PubSubClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
* messages between independent applications. Find more information at
* [Google Cloud Pub/Sub docs](https://cloud.google.com/pubsub/docs/).
*
* The [PUBSUB_EMULATOR_HOST](https://cloud.google.com/pubsub/emulator#env) environment variable
* from the gcloud SDK is honored, otherwise the actual API endpoint will be used.
* To enable the [Google Cloud Pub/Sub Emulator](https://cloud.google.com/pubsub/emulator),
* set the [`PUBSUB_EMULATOR_HOST`](https://cloud.google.com/pubsub/emulator#env)
* environment variable.
*
* Example:
* ```
Expand All @@ -44,6 +45,18 @@
*
* $pubsub = new PubSubClient();
* ```
*
* ```
* // Using the Pub/Sub Emulator
* use Google\Cloud\ServiceBuilder;
*
* // Be sure to use the port specified when starting the emulator.
* // `8900` is used as an example only.
* putenv('PUBSUB_EMULATOR_HOST=http://localhost:8900');
*
* $cloud = new ServiceBuilder();
* $pubsub = $cloud->pubsub();
* ```
*/
class PubSubClient
{
Expand Down