Skip to content

Commit f53126b

Browse files
committed
Separated grpc options to own section: grpc
1 parent 37d3862 commit f53126b

File tree

9 files changed

+22
-19
lines changed

9 files changed

+22
-19
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,19 +562,22 @@ $config = [
562562
$ydb = new \YdbPlatform\Ydb\Ydb($config);
563563
```
564564

565-
## gRPC options
565+
## gRPC
566566

567+
### gRPC client's options
567568
You can customize the gRPC client's behavior by setting options in config array
568569

569570
Example of using:
570571
```php
571572
$config = [
572573
// ...
573-
'opts' => [
574-
'grpc.max_receive_message_length' => 8*1024*1024,
575-
'grpc.default_compression_algorithm' => 2,
576-
'grpc.default_compression_level' => 2,
574+
'grpc' => [
575+
'opts' => [
576+
'grpc.max_receive_message_length' => 8*1024*1024,
577+
'grpc.default_compression_algorithm' => 2,
578+
'grpc.default_compression_level' => 2,
579+
],
577580
],
578-
]
581+
];
579582
$ydb = new \YdbPlatform\Ydb\Ydb($config);
580583
```

src/AuthService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(Ydb $ydb, $logger)
2828
{
2929
$this->ydb = $ydb;
3030
$this->logger = $logger;
31-
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());
31+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
3232
$this->credentials = $ydb->iam();
3333
$this->meta = [
3434
'x-ydb-database' => [$ydb->database()],

src/Discovery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
4343
{
4444
$this->ydb = $ydb;
4545

46-
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());
46+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
4747

4848
$this->meta = $ydb->meta();
4949

src/Operations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
3838
{
3939
$this->ydb = $ydb;
4040

41-
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());
41+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
4242

4343
$this->meta = $ydb->meta();
4444

src/Scheme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
4141
{
4242
$this->ydb = $ydb;
4343

44-
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());
44+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
4545

4646
$this->meta = $ydb->meta();
4747

src/Scripting.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null)
3838
{
3939
$this->ydb = $ydb;
4040

41-
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());
41+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
4242

4343
$this->meta = $ydb->meta();
4444

src/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct(Ydb $ydb, LoggerInterface $logger = null, Retry &$re
7575
{
7676
$this->ydb = $ydb;
7777

78-
$this->client = new ServiceClient($ydb->endpoint(), $ydb->opts());
78+
$this->client = new ServiceClient($ydb->endpoint(), $ydb->grpcOpts());
7979

8080
$this->meta = $ydb->meta();
8181

src/Traits/RequestTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ protected function handleGrpcStatus($service, $method, $status)
193193
if ($this->ydb->needDiscovery() && count($this->ydb->cluster()->all()) > 0){
194194
$endpoint = $this->ydb->cluster()->all()[array_rand($this->ydb->cluster()->all())]->endpoint();
195195
}
196-
$this->client = new $this->client($endpoint, $this->ydb->opts());
196+
$this->client = new $this->client($endpoint, $this->ydb->grpcOpts());
197197
if (isset(self::$grpcExceptions[$status->code])) {
198198
throw new self::$grpcExceptions[$status->code]($message);
199199
} else {

src/Ydb.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Ydb
4040
/**
4141
* @var array
4242
*/
43-
protected $opts;
43+
protected $grpc_config;
4444

4545
/**
4646
* @var Iam
@@ -111,7 +111,7 @@ public function __construct($config = [], LoggerInterface $logger = null)
111111
$this->endpoint = $config['endpoint'] ?? null;
112112
$this->database = $config['database'] ?? null;
113113
$this->iam_config = $config['iam_config'] ?? [];
114-
$this->opts = $config['opts'] ?? [];
114+
$this->grpc_config = (array) ($config['grpc'] ?? []);
115115

116116
if (!is_null($logger) && isset($config['logger'])){
117117
throw new \Exception('Logger set in 2 places');
@@ -179,12 +179,12 @@ public function meta(): array
179179
return $meta;
180180
}
181181

182-
public function opts(): array
182+
public function grpcOpts(): array
183183
{
184-
$opts = $this->opts;
185-
$opts['credentials'] = $this->iam()->getCredentials();
184+
$grpcOpts = (array) ($this->grpc_config['opts'] ?? []);
185+
$grpcOpts['credentials'] = $this->iam()->getCredentials();
186186

187-
return $opts;
187+
return $grpcOpts;
188188
}
189189

190190
/**

0 commit comments

Comments
 (0)