|
27 | 27 | use Google\Cloud\Core\ArrayTrait; |
28 | 28 | use Google\Cloud\Core\ClientTrait; |
29 | 29 | use Google\Cloud\Core\DetectProjectIdTrait; |
| 30 | +use Google\Cloud\Core\EmulatorTrait; |
30 | 31 | use Google\Cloud\Core\Int64; |
31 | 32 | use Google\Cloud\Core\TimestampTrait; |
32 | 33 | use Google\Cloud\Datastore\Query\AggregationQuery; |
@@ -99,6 +100,7 @@ class DatastoreClient |
99 | 100 | use TimestampTrait; |
100 | 101 | use ApiHelperTrait; |
101 | 102 | use ClientOptionsTrait; |
| 103 | + use EmulatorTrait; |
102 | 104 |
|
103 | 105 | const VERSION = '1.34.0'; |
104 | 106 |
|
@@ -212,9 +214,33 @@ public function __construct(array $config = []) |
212 | 214 | 'emulatorHost' => $emulatorHost, |
213 | 215 | ]; |
214 | 216 |
|
215 | | - $gapicConfig = $this->buildClientOptions($config); |
216 | | - $this->projectId = $this->detectProjectId($gapicConfig); |
217 | | - $this->gapicClient = $this->getGapicClient($gapicConfig); |
| 217 | + $gapicOptions = $this->buildClientOptions($config); |
| 218 | + |
| 219 | + if (isset($gapicOptions['credentialsConfig']['scopes'])) { |
| 220 | + $options['credentialsConfig']['scopes'] = array_merge( |
| 221 | + $gapicOptions['credentialsConfig']['scopes'], |
| 222 | + $config['scopes'] |
| 223 | + ); |
| 224 | + } else { |
| 225 | + $options['credentialsConfig']['scopes'] = $config['scopes']; |
| 226 | + } |
| 227 | + |
| 228 | + if ($emulatorHost) { |
| 229 | + $emulatorConfig = $this->emulatorGapicConfig($emulatorHost); |
| 230 | + $gapicOptions = array_merge( |
| 231 | + $gapicOptions, |
| 232 | + $emulatorConfig |
| 233 | + ); |
| 234 | + } else { |
| 235 | + $gapicOptions['credentials'] = $this->createCredentialsWrapper( |
| 236 | + $gapicOptions['credentials'], |
| 237 | + $gapicOptions['credentialsConfig'], |
| 238 | + $gapicOptions['universeDomain'] |
| 239 | + ); |
| 240 | + } |
| 241 | + |
| 242 | + $this->projectId = $this->detectProjectId($gapicOptions); |
| 243 | + $this->gapicClient = $this->getGapicClient($gapicOptions); |
218 | 244 |
|
219 | 245 | // The second parameter here should change to a variable |
220 | 246 | // when gRPC support is added for variable encoding. |
|
0 commit comments