Skip to content

Commit

Permalink
move code to another SpannerClient.php
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouyihaiDing committed Jun 29, 2018
1 parent 1bb8dd4 commit c55baa3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 120 deletions.
14 changes: 14 additions & 0 deletions Spanner/src/SpannerClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public function __construct(array $config = [])
'projectIdRequired' => true
];

if (isset($config['enable-gcp'])) {
$api = 'spanner';
$conf_path = "./../../$api.grpc.config";
$this->enableChonnectionManagement($conf_path, &$config);
}

$this->connection = new Grpc($this->configureAuthentication($config));
$this->returnInt64AsObject = $config['returnInt64AsObject'];

Expand Down Expand Up @@ -170,6 +176,14 @@ public function __construct(array $config = [])
]);
}

private function enableChonnectionManagement($conf_path, $options) {
// TODO: move this function to gax.
$conf = new \Grpc\Gcp\ApiConfig();
$conf->mergeFromJsonString($string = file_get_contents($conf_path));
$config = \Google\Cloud\Grpc($conf);
$options['grpc_call_invoker'] = $config->callInvoker();
}

/**
* Get a Batch Client.
*
Expand Down
13 changes: 0 additions & 13 deletions Spanner/src/V1/Gapic/SpannerGapicClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,23 +308,10 @@ public static function parseName($formattedName, $template = null)
*/
public function __construct(array $options = [])
{
if (isset($options['enable-gcp'])) {
$api = 'spanner';
$conf_path = "./../../$api.grpc.config";
$this->enableChonnectionManagement($conf_path, &$options);
}
$clientOptions = $this->buildClientOptions($options);
$this->setClientOptions($clientOptions);
}

private function enableChonnectionManagement($conf_path, $options) {
// TODO: move this function to gax.
$conf = new \Grpc\Gcp\ApiConfig();
$conf->mergeFromJsonString($string = file_get_contents($conf_path));
$config = \Google\Cloud\Grpc($conf);
$options['grpc_call_invoker'] = $config->callInvoker();
}

/**
* Creates a new session. A session can be used to perform
* transactions that read and/or modify data in a Cloud Spanner database.
Expand Down
107 changes: 0 additions & 107 deletions Spanner/tests/Unit/V1/SpannerClientEnableGCPTest.php

This file was deleted.

6 changes: 6 additions & 0 deletions spanner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
require('./vendor/autoload.php');
$spanner = new SpannerClient(['projectId' => 'ddyihai-firestore',
'enable_gcp' => true,
]);

0 comments on commit c55baa3

Please sign in to comment.