1818namespace Google \Cloud \Spanner ;
1919
2020use Closure ;
21- use Google \Cloud \Core \LongRunning \LongRunningOperation ;
22- use Google \Cloud \Core \LongRunning \LongRunningGapicConnection ;
2321use Google \Cloud \Core \Exception \NotFoundException ;
2422use Google \Cloud \Core \Iam \IamManager ;
2523use Google \Cloud \Core \Iterator \ItemIterator ;
24+ use Google \Cloud \Core \LongRunning \LongRunningClientConnection ;
25+ use Google \Cloud \Core \LongRunning \LongRunningOperation ;
2626use Google \Cloud \Core \RequestHandler ;
2727use Google \Cloud \Spanner \Admin \Database \V1 \Client \DatabaseAdminClient ;
2828use Google \Cloud \Spanner \Admin \Database \V1 \ListBackupsRequest ;
3131use Google \Cloud \Spanner \Admin \Instance \V1 \CreateInstanceRequest ;
3232use Google \Cloud \Spanner \Admin \Instance \V1 \DeleteInstanceRequest ;
3333use Google \Cloud \Spanner \Admin \Instance \V1 \GetInstanceRequest ;
34- use Google \Cloud \Spanner \Admin \Instance \V1 \Instance as InstanceProto ;
3534use Google \Cloud \Spanner \Admin \Instance \V1 \Instance \State ;
3635use Google \Cloud \Spanner \Admin \Instance \V1 \UpdateInstanceRequest ;
3736use Google \Cloud \Spanner \Session \SessionPoolInterface ;
3837use Google \Cloud \Spanner \V1 \Client \SpannerClient as GapicSpannerClient ;
3938use Google \LongRunning \ListOperationsRequest ;
39+ use Google \LongRunning \Operation as OperationProto ;
4040
4141/**
4242 * Represents a Cloud Spanner instance
@@ -84,6 +84,8 @@ class Instance
8484 */
8585 private $ projectName ;
8686
87+ private bool $ returnInt64AsObject ;
88+
8789 /**
8890 * Create an object representing a Cloud Spanner instance.
8991 *
@@ -95,11 +97,7 @@ class Instance
9597 * @param Serializer $serializer The serializer instance to encode/decode messages.
9698 * @param string $projectId The project ID.
9799 * @param string $name The instance name or ID.
98- * @param bool $returnInt64AsObject [optional] If true, 64 bit integers will be
99- * returned as a {@see \Google\Cloud\Core\Int64} object for 32 bit platform
100- * compatibility. **Defaults to** false.
101- * @param array $info [optional] A representation of the instance object.
102- * @param array $options [optional]{
100+ * @param array $options {
103101 * Instance options
104102 *
105103 * @type array $directedReadOptions Directed read options.
@@ -108,7 +106,11 @@ class Instance
108106 * {@see \Google\Cloud\Spanner\V1\DirectedReadOptions\ReplicaSelection\Type} to set a value.
109107 * @type bool $routeToLeader Enable/disable Leader Aware Routing.
110108 * **Defaults to** `true` (enabled).
109+ * @type bool $returnInt64AsObject If true, 64 bit integers will be
110+ * returned as a {@see \Google\Cloud\Core\Int64} object for 32 bit platform
111+ * compatibility. **Defaults to** false.
111112 * }
113+ * @param array $info A representation of the instance object.
112114 */
113115 public function __construct (
114116 private GapicSpannerClient $ spannerClient ,
@@ -117,14 +119,14 @@ public function __construct(
117119 private Serializer $ serializer ,
118120 private string $ projectId ,
119121 private string $ name ,
120- private bool $ returnInt64AsObject = false ,
122+ array $ options = [] ,
121123 private array $ info = [],
122- array $ options = []
123124 ) {
124125 $ this ->name = $ this ->fullyQualifiedInstanceName ($ name , $ projectId );
125126 $ this ->directedReadOptions = $ options ['directedReadOptions ' ] ?? [];
126127 $ this ->routeToLeader = $ options ['routeToLeader ' ] ?? true ;
127128 $ this ->defaultQueryOptions = $ options ['defaultQueryOptions ' ] ?? [];
129+ $ this ->returnInt64AsObject = $ options ['returnInt64AsObject ' ] ?? false ;
128130 $ this ->projectName = InstanceAdminClient::projectName ($ projectId );
129131 }
130132
@@ -795,7 +797,7 @@ private function fieldMask(array $instanceArray): array
795797 */
796798 public function createInstanceArray (
797799 array $ instanceArray ,
798- InstanceConfiguration $ config = null
800+ ? InstanceConfiguration $ config = null
799801 ): array {
800802 return $ instanceArray + [
801803 'name ' => $ this ->name ,
@@ -810,7 +812,7 @@ public function createInstanceArray(
810812 *
811813 * Example:
812814 * ```
813- * $operation = $spanner ->resumeOperation($operationName);
815+ * $operation = $instance ->resumeOperation($operationName);
814816 * ```
815817 *
816818 * @param string $operationName The Long Running Operation name.
@@ -819,7 +821,7 @@ public function createInstanceArray(
819821 public function resumeOperation ($ operationName , array $ options = []): LongRunningOperation
820822 {
821823 return new LongRunningOperation (
822- new LongRunningGapicConnection ($ this ->instanceAdminClient , $ this ->serializer ),
824+ new LongRunningClientConnection ($ this ->instanceAdminClient , $ this ->serializer ),
823825 $ operationName ,
824826 [
825827 [
@@ -840,7 +842,7 @@ public function resumeOperation($operationName, array $options = []): LongRunnin
840842 *
841843 * Example:
842844 * ```
843- * $operations = $backup ->longRunningOperations();
845+ * $operations = $instance ->longRunningOperations();
844846 * ```
845847 *
846848 * @param array $options [optional] {
@@ -866,7 +868,13 @@ public function longRunningOperations(array $options = []): ItemIterator
866868 return $ this ->buildLongRunningIterator (
867869 [$ this ->instanceAdminClient ->getOperationsClient (), 'listOperations ' ],
868870 $ request ,
869- $ callOptions
871+ $ callOptions ,
872+ function (OperationProto $ operation ) {
873+ return $ this ->resumeOperation (
874+ $ operation ->getName (),
875+ $ this ->handleResponse ($ operation )
876+ );
877+ }
870878 );
871879 }
872880
@@ -881,13 +889,13 @@ private function instanceResultFunction(): Closure
881889 $ this ->serializer ,
882890 $ this ->projectId ,
883891 $ name ['instance ' ],
884- $ this ->returnInt64AsObject ,
885- $ result ,
886892 [
887893 'directedReadOptions ' => $ this ->directedReadOptions ,
888894 'routeToLeader ' => $ this ->routeToLeader ,
889895 'defaultQueryOptions ' => $ this ->defaultQueryOptions ,
890- ]
896+ 'returnInt64AsObject ' => $ this ->returnInt64AsObject ,
897+ ],
898+ $ result ,
891899 );
892900 };
893901 }
0 commit comments