-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
141 changed files
with
24,885 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.