Skip to content

Commit

Permalink
Add support for the Datastore emulator (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpedrie authored and dwsupplee committed Oct 4, 2016
1 parent f7c3831 commit 80ea81b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
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

0 comments on commit 80ea81b

Please sign in to comment.