Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCBC-1004: Insert ABI version tag into PHP extension namespace #187

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
436 changes: 436 additions & 0 deletions .github/workflows/versions.yml

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions Couchbase/BinaryCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public function name(): string
*/
public function append(string $id, string $value, ?AppendOptions $options = null): MutationResult
{
$response = Extension\documentAppend(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentAppend';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand All @@ -107,7 +108,8 @@ public function append(string $id, string $value, ?AppendOptions $options = null
*/
public function prepend(string $id, string $value, ?PrependOptions $options = null): MutationResult
{
$response = Extension\documentPrepend(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentPrepend';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand All @@ -133,7 +135,8 @@ public function prepend(string $id, string $value, ?PrependOptions $options = nu
*/
public function increment(string $id, ?IncrementOptions $options = null): CounterResult
{
$response = Extension\documentIncrement(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentIncrement';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand All @@ -158,7 +161,8 @@ public function increment(string $id, ?IncrementOptions $options = null): Counte
*/
public function decrement(string $id, ?DecrementOptions $options = null): CounterResult
{
$response = Extension\documentDecrement(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentDecrement';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down
14 changes: 10 additions & 4 deletions Couchbase/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function __construct(string $name, $core)
{
$this->name = $name;
$this->core = $core;
Extension\openBucket($this->core, $this->name);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\openBucket';
$function($this->core, $this->name);
}

/**
Expand Down Expand Up @@ -128,7 +129,9 @@ public function viewQuery(string $designDoc, string $viewName, ?ViewOptions $opt
$opts = ViewOptions::export($options);
$namespace = $opts["namespace"];

$result = Extension\viewQuery($this->core, $this->name, $designDoc, $viewName, $namespace, $opts);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\viewQuery';

$result = $function($this->core, $this->name, $designDoc, $viewName, $namespace, $opts);

return new ViewResult($result);
}
Expand Down Expand Up @@ -183,7 +186,9 @@ public function ping($services = null, $reportId = null)
if ($reportId != null) {
$options['reportId'] = $reportId;
}
return Extension\ping($this->core, $options);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\ping';

return $function($this->core, $options);
}

/**
Expand All @@ -200,6 +205,7 @@ public function diagnostics(?string $reportId = null)
if ($reportId == null) {
$reportId = uniqid();
}
return Extension\diagnostics($this->core, $reportId);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\diagnostics';
return $function($this->core, $reportId);
}
}
36 changes: 24 additions & 12 deletions Couchbase/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public function __construct(string $connectionString, ClusterOptions $options)
) {
throw new InvalidArgumentException("Please use Cluster::connect() to connect to CNG.");
}
$this->connectionHash = hash("sha256", sprintf("--%s--%s--", $connectionString, $options->authenticatorHash()));
$this->core = Extension\createConnection($this->connectionHash, $connectionString, $options->export());
ExtensionNamespaceResolver::defineExtensionNamespace();
$this->connectionHash = hash("sha256", sprintf("--%s--%s--%s--", $connectionString, $options->authenticatorHash(), COUCHBASE_EXTENSION_NAMESPACE));
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\createConnection';
$this->core = $function($this->connectionHash, $connectionString, $options->export());
$this->options = $options;
}

Expand Down Expand Up @@ -136,7 +138,8 @@ function (string $connectionString, ClusterOptions $options) {
*/
public static function notifyFork(string $event)
{
return Extension\notifyFork($event);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\notifyFork';
return $function($event);
}

/**
Expand Down Expand Up @@ -167,7 +170,8 @@ public function bucket(string $name): BucketInterface
*/
public function query(string $statement, ?QueryOptions $options = null): QueryResult
{
$result = Extension\query($this->core, $statement, QueryOptions::export($options));
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\query';
$result = $function($this->core, $statement, QueryOptions::export($options));

return new QueryResult($result, QueryOptions::getTranscoder($options));
}
Expand All @@ -186,7 +190,8 @@ public function query(string $statement, ?QueryOptions $options = null): QueryRe
*/
public function analyticsQuery(string $statement, ?AnalyticsOptions $options = null): AnalyticsResult
{
$result = Extension\analyticsQuery($this->core, $statement, AnalyticsOptions::export($options));
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\analyticsQuery';
$result = $function($this->core, $statement, AnalyticsOptions::export($options));

return new AnalyticsResult($result, AnalyticsOptions::getTranscoder($options));
}
Expand All @@ -204,7 +209,8 @@ public function analyticsQuery(string $statement, ?AnalyticsOptions $options = n
*/
public function searchQuery(string $indexName, SearchQuery $query, ?SearchOptions $options = null): SearchResult
{
$result = Extension\searchQuery($this->core, $indexName, json_encode($query), SearchOptions::export($options));
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\searchQuery';
$result = $function($this->core, $indexName, json_encode($query), SearchOptions::export($options));

return new SearchResult($result);
}
Expand All @@ -230,12 +236,14 @@ public function search(string $indexName, SearchRequest $request, ?SearchOptions
$query = $exportedRequest['searchQuery'];

if (!$exportedRequest['vectorSearch']) {
$result = Extension\searchQuery($this->core, $indexName, json_encode($query), $exportedOptions);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\searchQuery';
$result = $function($this->core, $indexName, json_encode($query), $exportedOptions);
return new SearchResult($result);
}

$vectorSearch = $exportedRequest['vectorSearch'];
$result = Extension\vectorSearch($this->core, $indexName, json_encode($query), json_encode($vectorSearch), $exportedOptions, VectorSearchOptions::export($vectorSearch->options()));
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\vectorSearch';
$result = $function($this->core, $indexName, json_encode($query), json_encode($vectorSearch), $exportedOptions, VectorSearchOptions::export($vectorSearch->options()));
return new SearchResult($result);
}

Expand Down Expand Up @@ -318,7 +326,8 @@ public function ping($services = null, $reportId = null)
if ($reportId != null) {
$options['reportId'] = $reportId;
}
return Extension\ping($this->core, $options);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\ping';
return $function($this->core, $options);
}

/**
Expand All @@ -334,7 +343,8 @@ public function diagnostics(?string $reportId = null)
if ($reportId == null) {
$reportId = uniqid();
}
return Extension\diagnostics($this->core, $reportId);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\diagnostics';
return $function($this->core, $reportId);
}

/**
Expand All @@ -359,7 +369,8 @@ public function transactions(?TransactionsConfiguration $config = null): Transac
*/
public function version(string $bucketName): ?string
{
return Extension\clusterVersion($this->core, $bucketName);
$function = COUCHBASE_EXTENSION_NAMESPACE . "\\clusterVersion";
return $function($this->core, $bucketName);
}

/**
Expand All @@ -371,7 +382,8 @@ public function version(string $bucketName): ?string
*/
public function replicasConfiguredFor(string $bucketName): bool
{
return Extension\replicasConfiguredForBucket($this->core, $bucketName);
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\replicasConfiguredForBucket';
return $function($this->core, $bucketName);
}

/**
Expand Down
58 changes: 38 additions & 20 deletions Couchbase/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public function name(): string
*/
public function get(string $id, ?GetOptions $options = null): GetResult
{
$response = Extension\documentGet(
$this->core,
$function = COUCHBASE_EXTENSION_NAMESPACE . "\\documentGet";
$response = $function($this->core,
$this->bucketName,
$this->scopeName,
$this->name,
Expand All @@ -139,7 +139,8 @@ public function get(string $id, ?GetOptions $options = null): GetResult
*/
public function exists(string $id, ?ExistsOptions $options = null): ExistsResult
{
$response = Extension\documentExists(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentExists';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand All @@ -166,7 +167,8 @@ public function exists(string $id, ?ExistsOptions $options = null): ExistsResult
*/
public function getAndLock(string $id, int $lockTimeSeconds, ?GetAndLockOptions $options = null): GetResult
{
$response = Extension\documentGetAndLock(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentGetAndLock';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -198,7 +200,8 @@ public function getAndTouch(string $id, $expiry, ?GetAndTouchOptions $options =
} else {
$expirySeconds = (int)$expiry;
}
$response = Extension\documentGetAndTouch(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentGetAndTouch';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand All @@ -225,7 +228,8 @@ public function getAndTouch(string $id, $expiry, ?GetAndTouchOptions $options =
*/
public function getAnyReplica(string $id, ?GetAnyReplicaOptions $options = null): GetReplicaResult
{
$response = Extension\documentGetAnyReplica(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentGetAnyReplica';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand All @@ -250,7 +254,8 @@ public function getAnyReplica(string $id, ?GetAnyReplicaOptions $options = null)
*/
public function getAllReplicas(string $id, ?GetAllReplicasOptions $options = null): array
{
$responses = Extension\documentGetAllReplicas(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentGetAllReplicas';
$responses = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -281,7 +286,8 @@ function (array $response) use ($options) {
public function upsert(string $id, $value, ?UpsertOptions $options = null): MutationResult
{
$encoded = UpsertOptions::encodeDocument($options, $value);
$response = Extension\documentUpsert(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentUpsert';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -310,7 +316,8 @@ public function upsert(string $id, $value, ?UpsertOptions $options = null): Muta
public function insert(string $id, $value, ?InsertOptions $options = null): MutationResult
{
$encoded = InsertOptions::encodeDocument($options, $value);
$response = Extension\documentInsert(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentInsert';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -340,7 +347,8 @@ public function insert(string $id, $value, ?InsertOptions $options = null): Muta
public function replace(string $id, $value, ?ReplaceOptions $options = null): MutationResult
{
$encoded = ReplaceOptions::encodeDocument($options, $value);
$response = Extension\documentReplace(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentReplace';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -368,7 +376,8 @@ public function replace(string $id, $value, ?ReplaceOptions $options = null): Mu
*/
public function remove(string $id, ?RemoveOptions $options = null): MutationResult
{
$response = Extension\documentRemove(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentRemove';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -396,7 +405,8 @@ public function remove(string $id, ?RemoveOptions $options = null): MutationResu
*/
public function unlock(string $id, string $cas, ?UnlockOptions $options = null): Result
{
$response = Extension\documentUnlock(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentUnlock';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -428,7 +438,8 @@ public function touch(string $id, $expiry, ?TouchOptions $options = null): Mutat
} else {
$expirySeconds = (int)$expiry;
}
$response = Extension\documentTouch(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentTouch';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -464,7 +475,8 @@ function (LookupInSpec $item) {
if ($options != null && $options->needToFetchExpiry()) {
$encoded[] = ['opcode' => 'get', 'isXattr' => true, 'path' => LookupInMacro::EXPIRY_TIME];
}
$response = Extension\documentLookupIn(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentLookupIn';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -500,7 +512,8 @@ function (LookupInSpec $item) {
if ($options != null && $options->needToFetchExpiry()) {
$encoded[] = ['opcode' => 'get', 'isXattr' => true, 'path' => LookupInMacro::EXPIRY_TIME];
}
$response = Extension\documentLookupInAnyReplica(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentLookupInAnyReplica';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -537,7 +550,8 @@ function (LookupInSpec $item) {
if ($options != null && $options->needToFetchExpiry()) {
$encoded[] = ['opcode' => 'get', 'isXattr' => true, 'path' => LookupInMacro::EXPIRY_TIME];
}
$responses = Extension\documentLookupInAllReplicas(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentLookupInAllReplicas';
$responses = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -576,7 +590,8 @@ function (MutateInSpec $item) use ($options) {
},
$specs
);
$response = Extension\documentMutateIn(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentMutateIn';
$response = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand All @@ -600,7 +615,8 @@ function (MutateInSpec $item) use ($options) {
*/
public function getMulti(array $ids, ?GetOptions $options = null): array
{
$responses = Extension\documentGetMulti(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentGetMulti';
$responses = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -666,7 +682,8 @@ public function scan(ScanType $scanType, ?ScanOptions $options = null): ScanResu
*/
public function removeMulti(array $entries, ?RemoveOptions $options = null): array
{
$responses = Extension\documentRemoveMulti(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentRemoveMulti';
$responses = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down Expand Up @@ -712,7 +729,8 @@ function (array $entry) use ($options) {
},
$entries
);
$responses = Extension\documentUpsertMulti(
$function = COUCHBASE_EXTENSION_NAMESPACE . '\\documentUpsertMulti';
$responses = $function(
$this->core,
$this->bucketName,
$this->scopeName,
Expand Down
Loading
Loading