Skip to content

Commit

Permalink
Merge branch 'spanner'
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpedrie committed May 18, 2017
2 parents 452e730 + 33f743a commit d15968c
Show file tree
Hide file tree
Showing 141 changed files with 24,885 additions and 283 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This client supports the following Google Cloud Platform services at a [Beta](#v

This client supports the following Google Cloud Platform services at an [Alpha](#versioning) quality level:
* [Google Cloud Pub/Sub](#google-cloud-pubsub-alpha) (Alpha)
* [Cloud Spanner](#cloud-spanner-alpha) (Alpha)
* [Google Cloud Speech](#google-cloud-speech-alpha) (Alpha)
* [Google Cloud Video Intelligence](#google-cloud-video-intelligence-alpha) (Alpha)
* [Google Stackdriver Trace](#google-stackdriver-trace-alpha) (Alpha)
Expand Down Expand Up @@ -391,6 +392,43 @@ Google Cloud Pub/Sub can be installed separately by requiring the `google/cloud-
$ require google/cloud-pubsub
```

## Cloud Spanner (Alpha)

- [API Documentation](http://googlecloudplatform.github.io/google-cloud-php/#/docs/latest/spanner/spannerclient)
- [Official Documentation](https://cloud.google.com/spanner/docs)

#### Preview

```php
require 'vendor/autoload.php';

use Google\Cloud\Spanner\SpannerClient;

$spanner = new SpannerClient([
'projectId' => 'my_project'
]);

$db = $spanner->connect('my-instance', 'my-database');

$userQuery = $db->execute('SELECT * FROM Users WHERE id = @id', [
'parameters' => [
'id' => $userId
]
]);

$user = $userQuery->rows()->current();

echo 'Hello ' . $user['firstName'];
```

#### google/cloud-spanner

Cloud Spanner can be installed separately by requiring the `google/cloud-spanner` composer package:

```
$ require google/cloud-spanner
```

## Google Cloud Speech (Alpha)

- [API Documentation](http://googlecloudplatform.github.io/google-cloud-php/#/docs/latest/speech/speechclient)
Expand Down
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"natural language",
"pubsub",
"pub sub",
"spanner",
"speech",
"storage",
"gcs",
Expand Down Expand Up @@ -56,11 +57,13 @@
"erusev/parsedown": "^1.6",
"vierbergenlars/php-semver": "^3.0",
"google/proto-client-php": "^0.13",
"google/gax": "^0.8"
"google/gax": "^0.9",
"symfony/lock": "dev-master#1ba6ac9"
},
"suggest": {
"google/gax": "Required to support gRPC",
"google/proto-client-php": "Required to support gRPC"
"google/proto-client-php": "Required to support gRPC",
"symfony/lock": "Required for the Spanner cached based session pool. Please require the following commit: dev-master#1ba6ac9"
},
"autoload": {
"psr-4": {
Expand All @@ -70,8 +73,10 @@
"autoload-dev": {
"psr-4": {
"Google\\Cloud\\Dev\\": "dev/src",
"Google\\Cloud\\Tests\\System\\": "tests/system"
}
"Google\\Cloud\\Tests\\System\\": "tests/system",
"Google\\Cloud\\Tests\\Unit\\": "tests/unit"
},
"files": ["dev/src/Functions.php"]
},
"scripts": {
"google-cloud": "dev/google-cloud"
Expand Down
29 changes: 29 additions & 0 deletions dev/src/Functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Google\Cloud\Dev;

/**
* Create a test stub which extends a real class and allows overriding of private properties.
*
* @param string $extends The fully-qualified name of the class to extend.
* @param array $args An array of constructor arguments to use when creating the stub.
* @param array $props A list of private properties on which to enable overrriding.
* @return mixed
*/
function stub($extends, array $args = [], array $props = [])
{
if (empty($props)) {
$props = ['connection'];
}

$tpl = 'class %s extends %s {private $___props = \'%s\'; use \Google\Cloud\Dev\StubTrait; }';

$name = 'Stub'. sha1($extends);

if (!class_exists($name)) {
eval(sprintf($tpl, $name, $extends, json_encode($props)));
}

$reflection = new \ReflectionClass($name);
return $reflection->newInstanceArgs($args);
}
6 changes: 3 additions & 3 deletions dev/src/Snippet/SnippetTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function snippetFromClass($class, $indexOrName = 0)

self::$coverage->cover($snippet->identifier());

return $snippet;
return clone $snippet;
}

/**
Expand All @@ -77,7 +77,7 @@ public function snippetFromMagicMethod($class, $method, $indexOrName = 0)

self::$coverage->cover($identifier);

return $snippet;
return clone $snippet;
}

/**
Expand All @@ -100,6 +100,6 @@ public function snippetFromMethod($class, $method, $indexOrName = 0)

self::$coverage->cover($identifier);

return $snippet;
return clone $snippet;
}
}
55 changes: 55 additions & 0 deletions dev/src/StubTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Dev;

trait StubTrait
{
public function ___getProperty($prop)
{
$property = $this->___getPropertyReflector($prop);

$property->setAccessible(true);
return $property->getValue($this);
}

public function ___setProperty($prop, $value)
{
if (!in_array($prop, json_decode($this->___props))) {
throw new \BadMethodCallException(sprintf('Property %s cannot be overloaded', $prop));
}

$property = $this->___getPropertyReflector($prop);

$property->setAccessible(true);
$property->setValue($this, $value);
}

private function ___getPropertyReflector($property)
{
$trait = new \ReflectionClass($this);
$ref = $trait->getParentClass();

try {
$property = $ref->getProperty($property);
} catch (\ReflectionException $e) {
throw new \BadMethodCallException($e->getMessage());
}

return $property;
}
}
47 changes: 47 additions & 0 deletions docs/contents/cloud-spanner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"title": "Spanner",
"pattern": "spanner\/\\w{1,}",
"services": [{
"title": "SpannerClient",
"type": "spanner/spannerclient"
}, {
"title": "Configuration",
"type": "spanner/configuration"
}, {
"title": "Database",
"type": "spanner/database"
}, {
"title": "Instance",
"type": "spanner/instance"
}, {
"title": "Snapshot",
"type": "spanner/snapshot"
}, {
"title": "Transaction",
"type": "spanner/transaction"
}, {
"title": "Bytes",
"type": "spanner/bytes"
}, {
"title": "Date",
"type": "spanner/date"
}, {
"title": "Duration",
"type": "spanner/duration"
}, {
"title": "KeyRange",
"type": "spanner/keyrange"
}, {
"title": "KeySet",
"type": "spanner/keyset"
}, {
"title": "Result",
"type": "spanner/result"
}, {
"title": "Timestamp",
"type": "spanner/timestamp"
},{
"title": "CacheSessionPool",
"type": "spanner/session/cachesessionpool"
}]
}
8 changes: 8 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@
"master"
]
},
{
"id": "cloud-spanner",
"name": "google/cloud-spanner",
"defaultService": "spanner/spannerclient",
"versions": [
"master"
]
},
{
"id": "cloud-speech",
"name": "google/cloud-speech",
Expand Down
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<directory suffix=".php">src</directory>
<exclude>
<directory suffix=".php">src/*/V[!a-zA-Z]*</directory>
<directory suffix=".php">src/*/*/V[!a-zA-Z]*</directory>
<directory suffix=".php">src/*/*/*/V[!a-zA-Z]*</directory>
</exclude>
</whitelist>
</filter>
Expand Down
17 changes: 17 additions & 0 deletions src/Core/ArrayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,21 @@ private function isAssoc(array $arr)
{
return array_keys($arr) !== range(0, count($arr) - 1);
}

/**
* Just like array_filter(), but preserves falsey values except null.
*
* @param array $arr
* @return array
*/
private function arrayFilterRemoveNull(array $arr)
{
return array_filter($arr, function ($element) {
if (!is_null($element)) {
return true;
}

return false;
});
}
}
49 changes: 49 additions & 0 deletions src/Core/Exception/AbortedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Core\Exception;

/**
* Exception thrown when a transaction is aborted.
*/
class AbortedException extends ServiceException
{
/**
* Return the delay in seconds and nanos before retrying the failed request.
*
* @return array
*/
public function getRetryDelay()
{
$metadata = array_filter($this->metadata, function ($metadataItem) {
if (array_key_exists('retryDelay', $metadataItem)) {
return true;
}

return false;
});

if (count($metadata) === 0) {
return ['seconds' => 0, 'nanos' => 0];
}

return $metadata[0]['retryDelay'] + [
'seconds' => 0,
'nanos' => 0
];
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* Copyright 2016 Google Inc.
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -15,12 +15,13 @@
* limitations under the License.
*/

namespace Google\Cloud\Dev;
namespace Google\Cloud\Core\Exception;

trait SetStubConnectionTrait
/**
* Exception thrown when a request fails due to a failed precondition.
* In REST context, this exception indicates a status code 412.
*/
class FailedPreconditionException extends ServiceException
{
public function setConnection($conn)
{
$this->connection = $conn;
}

}
Loading

0 comments on commit d15968c

Please sign in to comment.