Skip to content

Commit 099ecea

Browse files
committed
consistency with constructor options
1 parent fb4467a commit 099ecea

7 files changed

Lines changed: 29 additions & 17 deletions

File tree

Spanner/src/Backup.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class Backup
5555
const STATE_READY = State::READY;
5656
const STATE_CREATING = State::CREATING;
5757

58+
private array $info;
59+
5860
/**
5961
* Create an object representing a Backup.
6062
*
@@ -66,17 +68,22 @@ class Backup
6668
* @param Instance $instance The instance in which the backup exists.
6769
* @param string $projectId The project ID.
6870
* @param string $name The backup name or ID.
69-
* @param array $info [optional] An array representing the backup resource.
71+
* @param array $options [Optional] {
72+
* Backup options.
73+
74+
* @type array $backup The backup info.
75+
* }
7076
*/
7177
public function __construct(
7278
private DatabaseAdminClient $databaseAdminClient,
7379
private Serializer $serializer,
7480
private Instance $instance,
7581
private string $projectId,
7682
private string $name,
77-
private array $info = []
83+
array $options = []
7884
) {
7985
$this->name = $this->fullyQualifiedBackupName($name);
86+
$this->info = $options['info'] ?? [];
8087
$this->optionsValidator = new OptionsValidator($serializer);
8188
}
8289

Spanner/src/Instance.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Instance
6767
private bool $routeToLeader;
6868
private string $projectName;
6969
private bool $returnInt64AsObject;
70+
private array $info;
7071

7172
/**
7273
* Create an object representing a Cloud Spanner instance.
@@ -91,8 +92,8 @@ class Instance
9192
* @type bool $returnInt64AsObject If true, 64 bit integers will be
9293
* returned as a {@see \Google\Cloud\Core\Int64} object for 32 bit platform
9394
* compatibility. **Defaults to** false.
95+
* @type array $instance An array representation of the instance object.
9496
* }
95-
* @param array $info A representation of the instance object.
9697
*/
9798
public function __construct(
9899
private GapicSpannerClient $spannerClient,
@@ -102,13 +103,13 @@ public function __construct(
102103
private string $projectId,
103104
private string $name,
104105
array $options = [],
105-
private array $info = [],
106106
) {
107107
$this->name = $this->fullyQualifiedInstanceName($name, $projectId);
108108
$this->directedReadOptions = $options['directedReadOptions'] ?? [];
109109
$this->routeToLeader = $options['routeToLeader'] ?? true;
110110
$this->defaultQueryOptions = $options['defaultQueryOptions'] ?? [];
111111
$this->returnInt64AsObject = $options['returnInt64AsObject'] ?? false;
112+
$this->info = $options['instance'] ?? [];
112113
$this->projectName = InstanceAdminClient::projectName($projectId);
113114
$this->optionsValidator = new OptionsValidator($serializer);
114115
}
@@ -582,7 +583,7 @@ public function backup(string $name, array $backup = []): Backup
582583
$this,
583584
$this->projectId,
584585
$name,
585-
$backup
586+
['backup' => $backup]
586587
);
587588
}
588589

@@ -892,8 +893,8 @@ private function instanceResultFunction(): Closure
892893
'routeToLeader' => $this->routeToLeader,
893894
'defaultQueryOptions' => $this->defaultQueryOptions,
894895
'returnInt64AsObject' => $this->returnInt64AsObject,
896+
'instance' => $result,
895897
],
896-
$result,
897898
);
898899
};
899900
}

Spanner/src/InstanceConfiguration.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ class InstanceConfiguration
5454
{
5555
use RequestTrait;
5656

57+
private array $info;
58+
5759
/**
5860
* Create an instance configuration object.
5961
*
@@ -63,17 +65,21 @@ class InstanceConfiguration
6365
* @param Serializer $serializer The serializer instance to encode/decode messages.
6466
* @param string $projectId The current project ID.
6567
* @param string $name The configuration name or ID.
66-
* @param array $info [optional] A service representation of the
67-
* configuration.
68+
* @param array $options [Optional] {
69+
* Instance Configuration options.
70+
71+
* @type array $instanceConfig The instance configuration info.
72+
* }
6873
*/
6974
public function __construct(
7075
private InstanceAdminClient $instanceAdminClient,
7176
private Serializer $serializer,
7277
private string $projectId,
7378
private string $name,
74-
private array $info = []
79+
private array $options = [],
7580
) {
7681
$this->name = $this->fullyQualifiedConfigName($name, $projectId);
82+
$this->info = $options['instanceConfig'] ?? [];
7783
$this->optionsValidator = new OptionsValidator($serializer);
7884
}
7985

@@ -411,7 +417,7 @@ private function instanceConfigResultFunction(): Closure
411417
$this->serializer,
412418
$this->projectId,
413419
$name['instance_config'],
414-
$result
420+
['instanceConfig' => $result],
415421
);
416422
};
417423
}

Spanner/src/SpannerClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public function instanceConfiguration($name, array $info = []): InstanceConfigur
443443
$this->serializer,
444444
$this->projectId,
445445
$name,
446-
$info
446+
['instanceConfig' => $info]
447447
);
448448
}
449449

@@ -561,8 +561,8 @@ public function instance(string $name, array $instance = []): Instance
561561
'routeToLeader' => $this->routeToLeader,
562562
'defaultQueryOptions' => $this->defaultQueryOptions,
563563
'returnInt64AsObject' => $this->returnInt64AsObject,
564+
'instance' => $instance,
564565
],
565-
$instance,
566566
);
567567
}
568568

Spanner/tests/Snippet/InstanceConfigurationTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function setUp(): void
6262
$this->serializer,
6363
self::PROJECT,
6464
self::CONFIG,
65-
[],
6665
);
6766
}
6867

@@ -95,7 +94,6 @@ public function testCreate()
9594
$this->serializer,
9695
self::PROJECT,
9796
self::CONFIG,
98-
[]
9997
);
10098
$snippet->addLocal('baseConfig', $baseConfig);
10199
$snippet->addLocal('options', []);

Spanner/tests/Unit/BackupTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function testReload()
258258
$this->instance->reveal(),
259259
self::PROJECT_ID,
260260
self::BACKUP,
261-
['name' => 'different-name']
261+
['backup' => ['name' => 'different-name']]
262262
);
263263

264264
$info = $backup->reload();

Spanner/tests/Unit/InstanceConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testInfo()
9090
$this->serializer,
9191
self::PROJECT_ID,
9292
self::NAME,
93-
$info
93+
['instanceConfig' => $info],
9494
);
9595

9696
$this->assertEquals($info, $instanceConfig->info());
@@ -173,7 +173,7 @@ public function testReload()
173173
$this->serializer,
174174
self::PROJECT_ID,
175175
self::NAME,
176-
$expected1
176+
['instanceConfig' => $expected1],
177177
);
178178

179179
$info1 = $instanceConfig->info();

0 commit comments

Comments
 (0)