@@ -24,9 +24,14 @@ class RESTv1 extends \GDS\Gateway
24
24
const MODE_UNSPECIFIED = 'UNSPECIFIED ' ;
25
25
26
26
/**
27
- * REST API Base Endpoint
27
+ * Client config keys.
28
28
*/
29
- private $ base_url = 'https://datastore.googleapis.com ' ;
29
+ const CONFIG_CLIENT_BASE_URL = 'base_url ' ;
30
+
31
+ /**
32
+ * Default Base URL to use.
33
+ */
34
+ const DEFAULT_BASE_URL = 'https://datastore.googleapis.com ' ;
30
35
31
36
/**
32
37
* @var ClientInterface
@@ -92,14 +97,16 @@ protected function initHttpClient()
92
97
$ obj_stack = HandlerStack::create ();
93
98
$ obj_stack ->push (ApplicationDefaultCredentials::getMiddleware (['https://www.googleapis.com/auth/datastore ' ]));
94
99
100
+ $ str_base_url = self ::DEFAULT_BASE_URL ;
101
+
95
102
if (getenv ("DATASTORE_EMULATOR_HOST " ) !== FALSE ) {
96
- $ this -> base_url = getenv ("DATASTORE_EMULATOR_HOST " );
103
+ $ str_base_url = getenv ("DATASTORE_EMULATOR_HOST " );
97
104
}
98
105
99
106
// Create the HTTP client
100
107
return new Client ([
101
108
'handler ' => $ obj_stack ,
102
- 'base_url ' => $ this -> base_url ,
109
+ 'base_url ' => $ str_base_url ,
103
110
'auth ' => 'google_auth ' // authorize all requests
104
111
]);
105
112
}
@@ -474,6 +481,22 @@ public function beginTransaction($bol_cross_group = FALSE)
474
481
return null ;
475
482
}
476
483
484
+ /**
485
+ * Get the base url from the client object.
486
+ *
487
+ * Note: If for some reason the client's base URL is not set then we will return the default endpoint.
488
+ *
489
+ * @return string
490
+ */
491
+ protected function getBaseUrl () {
492
+ $ str_base_url = $ this ->obj_http_client ->getConfig (self ::CONFIG_CLIENT_BASE_URL );
493
+ if (!empty ($ str_base_url )) {
494
+ return $ str_base_url ;
495
+ }
496
+
497
+ return self ::DEFAULT_BASE_URL ;
498
+ }
499
+
477
500
/**
478
501
* Build a URL for a Datastore action
479
502
*
@@ -482,7 +505,7 @@ public function beginTransaction($bol_cross_group = FALSE)
482
505
*/
483
506
private function actionUrl ($ str_action )
484
507
{
485
- return $ this ->base_url . '/v1/projects/ ' . $ this ->str_dataset_id . ': ' . $ str_action ;
508
+ return $ this ->getBaseUrl () . '/v1/projects/ ' . $ this ->str_dataset_id . ': ' . $ str_action ;
486
509
}
487
510
488
511
}
0 commit comments