Skip to content

Commit

Permalink
PCBC-969: move grpc dependencies to suggests section (#153)
Browse files Browse the repository at this point in the history
Hard dependency on gRPC in PHP might be problematic, so by relaxing the
requirement we allow users to choose whether to install gRPC and instead
check its presence runtime and throw exception if couchbase2:// protocol
is being used while the extensions are not loaded.
  • Loading branch information
avsej authored Mar 16, 2024
1 parent e199b7f commit 5c9cd1f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
/mkinstalldirs
/modules/
/package.xml
/composer.phar
/phpunit.result.cache
/run-tests.php
/src/.idea/
Expand Down
9 changes: 9 additions & 0 deletions Couchbase/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,17 @@ public static function connect(string $connectionString, ClusterOptions $options
return ClusterRegistry::connect($connectionString, $options);
}

/**
* @throws InvalidArgumentException if runtime dependencies are missing ("protobuf" and "grpc" modules)
*/
private static function enableProtostellar(): void
{
if (!extension_loaded("protobuf")) {
throw new InvalidArgumentException("couchbase2:// protocol requires protobuf extension");
}
if (!extension_loaded("grpc")) {
throw new InvalidArgumentException("couchbase2:// protocol requires grpc extension");
}
ClusterRegistry::registerConnectionHandler(
"/^protostellar:\/\//",
function (string $connectionString, ClusterOptions $options) {
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
"email": "[email protected]"
}
],
"require": {
"ext-json": "*",
"suggest": {
"ext-grpc": "^1.15",
"ext-protobuf": "^3.21",
"google/protobuf": "^3.21",
"grpc/grpc": "^1.42",
"google/common-protos": "^3.1"
},
"require": {
"ext-json": "*"
},
"require-dev": {
"ext-sockets": "*",
"phpunit/phpunit": "^9"
Expand Down

0 comments on commit 5c9cd1f

Please sign in to comment.