forked from googleapis/google-cloud-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce support for Cloud Spanner (googleapis#333)
- Loading branch information
Showing
111 changed files
with
15,648 additions
and
255 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
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
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
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,42 @@ | ||
<?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 | ||
{ | ||
public function getRetryDelay() | ||
{ | ||
$metadata = array_filter($this->options, function ($metadataItem) { | ||
if (array_key_exists('retryDelay', $metadataItem)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
$delay = $metadata[0]['retryDelay']; | ||
if (!isset($delay['seconds'])) { | ||
$delay['seconds'] = 0; | ||
} | ||
|
||
return $delay; | ||
} | ||
} |
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,27 @@ | ||
<?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 request fails due to a failed precondition. | ||
* In REST context, this exception indicates a status code 412. | ||
*/ | ||
class FailedPreconditionException extends ServiceException | ||
{ | ||
|
||
} |
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
Oops, something went wrong.