Skip to content

Commit f622abb

Browse files
authored
PCBC-960 Merge protostellar branch to master (#138)
* Migrate protostellar files * Update PS files * Move generated files * Updating PS files * Update tests to use interfaces, skip if Protostellar * Add management interfaces to classic * Change datastructures to use interfaces * Add PS support in Cluster * add grpc as dependency to composer, update package.xml, add/update scripts * Add validation check to lookupinresult methods * Cleaning * fix style * revert package.xml update * Update PS files * Update PS implementation files * Update exception mapping per RFC * Add PermissionDeniedException * Update package.xml * Update exception converter * undo test script changes * Add support for simple string sorting via FieldSorting
1 parent dac7e56 commit f622abb

File tree

406 files changed

+40012
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

406 files changed

+40012
-62
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "src/deps/couchbase-cxx-client"]
22
path = src/deps/couchbase-cxx-client
33
url = https://github.com/couchbaselabs/couchbase-cxx-client.git
4+
[submodule "src/deps/protostellar"]
5+
path = src/deps/protostellar
6+
url = https://github.com/couchbase/protostellar

Couchbase/Cluster.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ class Cluster implements ClusterInterface
5353
*/
5454
public function __construct(string $connectionString, ClusterOptions $options)
5555
{
56+
if (
57+
preg_match("/^protostellar:\/\//", $connectionString) ||
58+
preg_match("/^couchbase2:\/\//", $connectionString)
59+
) {
60+
throw new InvalidArgumentException("Please use Cluster::connect() to connect to CNG.");
61+
}
5662
$this->connectionHash = hash("sha256", sprintf("--%s--%s--", $connectionString, $options->authenticatorHash()));
5763
$this->core = Extension\createConnection($this->connectionHash, $connectionString, $options->export());
5864
$this->options = $options;
@@ -67,9 +73,33 @@ public static function connect(string $connectionString, ClusterOptions $options
6773
if (preg_match("/^couchbases?:\/\//", $connectionString)) {
6874
return new Cluster($connectionString, $options);
6975
}
76+
77+
if (
78+
preg_match("/^protostellar:\/\//", $connectionString) ||
79+
preg_match("/^couchbase2:\/\//", $connectionString)
80+
) {
81+
Cluster::enableProtostellar();
82+
}
7083
return ClusterRegistry::connect($connectionString, $options);
7184
}
7285

86+
private static function enableProtostellar(): void
87+
{
88+
ClusterRegistry::registerConnectionHandler(
89+
"/^protostellar:\/\//",
90+
function (string $connectionString, ClusterOptions $options) {
91+
return new Protostellar\Cluster($connectionString, $options);
92+
}
93+
);
94+
95+
ClusterRegistry::registerConnectionHandler(
96+
"/^couchbase2:\/\//",
97+
function (string $connectionString, ClusterOptions $options) {
98+
return new Protostellar\Cluster($connectionString, $options);
99+
}
100+
);
101+
}
102+
73103
/**
74104
* Returns a new bucket object.
75105
*

Couchbase/Datastructures/CouchbaseList.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use ArrayAccess;
2424
use ArrayIterator;
25-
use Couchbase\Collection;
25+
use Couchbase\CollectionInterface;
2626
use Couchbase\Exception\DocumentNotFoundException;
2727
use Couchbase\Exception\InvalidArgumentException;
2828
use Couchbase\Exception\PathMismatchException;
@@ -48,19 +48,19 @@
4848
class CouchbaseList implements Countable, IteratorAggregate, ArrayAccess
4949
{
5050
private string $id;
51-
private Collection $collection;
51+
private CollectionInterface $collection;
5252
private Options\CouchbaseList $options;
5353

5454
/**
5555
* CouchbaseList constructor.
5656
*
5757
* @param string $id identifier of the backing document.
58-
* @param Collection $collection collection instance, where the document will be stored
58+
* @param CollectionInterface $collection collection instance, where the document will be stored
5959
* @param Options\CouchbaseList|null $options
6060
*
6161
* @since 4.0.0
6262
*/
63-
public function __construct(string $id, Collection $collection, ?Options\CouchbaseList $options = null)
63+
public function __construct(string $id, CollectionInterface $collection, ?Options\CouchbaseList $options = null)
6464
{
6565
$this->id = $id;
6666
$this->collection = $collection;

Couchbase/Datastructures/CouchbaseMap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use ArrayAccess;
2424
use ArrayIterator;
25-
use Couchbase\Collection;
25+
use Couchbase\CollectionInterface;
2626
use Couchbase\Exception\DocumentNotFoundException;
2727
use Couchbase\Exception\InvalidArgumentException;
2828
use Couchbase\Exception\PathMismatchException;
@@ -44,19 +44,19 @@
4444
class CouchbaseMap implements Countable, IteratorAggregate, ArrayAccess
4545
{
4646
private string $id;
47-
private Collection $collection;
47+
private CollectionInterface $collection;
4848
private Options\CouchbaseMap $options;
4949

5050
/**
5151
* CouchbaseList constructor.
5252
*
5353
* @param string $id identifier of the backing document.
54-
* @param Collection $collection collection instance, where the document will be stored
54+
* @param CollectionInterface $collection collection instance, where the document will be stored
5555
* @param Options\CouchbaseMap|null $options
5656
*
5757
* @since 4.0.0
5858
*/
59-
public function __construct(string $id, Collection $collection, ?Options\CouchbaseMap $options = null)
59+
public function __construct(string $id, CollectionInterface $collection, ?Options\CouchbaseMap $options = null)
6060
{
6161
$this->id = $id;
6262
$this->collection = $collection;

Couchbase/Datastructures/CouchbaseQueue.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace Couchbase\Datastructures;
2222

2323
use ArrayIterator;
24-
use Couchbase\Collection;
24+
use Couchbase\CollectionInterface;
2525
use Couchbase\Exception\DocumentNotFoundException;
2626
use Couchbase\Exception\InvalidArgumentException;
2727
use Couchbase\Exception\PathNotFoundException;
@@ -41,19 +41,19 @@
4141
class CouchbaseQueue implements Countable, IteratorAggregate
4242
{
4343
private string $id;
44-
private Collection $collection;
44+
private CollectionInterface $collection;
4545
private Options\CouchbaseQueue $options;
4646

4747
/**
4848
* CouchbaseQueue constructor.
4949
*
5050
* @param string $id identifier of the backing document.
51-
* @param Collection $collection collection instance, where the document will be stored
51+
* @param CollectionInterface $collection collection instance, where the document will be stored
5252
* @param Options\CouchbaseQueue|null $options
5353
*
5454
* @since 4.0.0
5555
*/
56-
public function __construct(string $id, Collection $collection, ?Options\CouchbaseQueue $options = null)
56+
public function __construct(string $id, CollectionInterface $collection, ?Options\CouchbaseQueue $options = null)
5757
{
5858
$this->id = $id;
5959
$this->collection = $collection;

Couchbase/Datastructures/CouchbaseSet.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace Couchbase\Datastructures;
2222

2323
use ArrayIterator;
24-
use Couchbase\Collection;
24+
use Couchbase\CollectionInterface;
2525
use Couchbase\Exception\DocumentNotFoundException;
2626
use Couchbase\Exception\InvalidArgumentException;
2727
use Couchbase\Exception\PathExistsException;
@@ -40,17 +40,17 @@
4040
class CouchbaseSet implements Countable, IteratorAggregate
4141
{
4242
private string $id;
43-
private Collection $collection;
43+
private CollectionInterface $collection;
4444
private Options\CouchbaseSet $options;
4545

4646
/**
4747
* CouchbaseSet constructor.
4848
*
4949
* @param string $id identifier of the backing document.
50-
* @param Collection $collection collection instance, where the document will be stored
50+
* @param CollectionInterface $collection collection instance, where the document will be stored
5151
* @param Options\CouchbaseSet|null $options
5252
*/
53-
public function __construct(string $id, Collection $collection, ?Options\CouchbaseSet $options = null)
53+
public function __construct(string $id, CollectionInterface $collection, ?Options\CouchbaseSet $options = null)
5454
{
5555
$this->id = $id;
5656
$this->collection = $collection;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2014-Present Couchbase, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
declare(strict_types=1);
20+
21+
namespace Couchbase\Exception;
22+
23+
class PermissionDeniedException extends CouchbaseException
24+
{
25+
}

Couchbase/LookupInResult.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ public function content(int $index)
8181
public function contentByPath(string $path)
8282
{
8383
foreach ($this->fields as $field) {
84-
if ($field['path'] == $path) {
85-
if (!array_key_exists('exists', $field) || !$field['exists']) {
86-
throw new PathNotFoundException(sprintf("LookupIn path is not found for path: %s", $path));
84+
if (array_key_exists('path', $field)) {
85+
if ($field['path'] == $path) {
86+
if (!array_key_exists('exists', $field) || !$field['exists']) {
87+
throw new PathNotFoundException(sprintf("LookupIn path is not found for path: %s", $path));
88+
}
89+
return $this->transcoder->decode($field['value'], 0);
8790
}
88-
return $this->transcoder->decode($field['value'], 0);
8991
}
9092
}
9193
throw new OutOfBoundsException(sprintf("LookupIn result does not have entry for path: %s", $path));
@@ -102,7 +104,9 @@ public function contentByPath(string $path)
102104
public function exists(int $index): bool
103105
{
104106
if (array_key_exists($index, $this->fields)) {
105-
return $this->fields[$index]['exists'];
107+
if (array_key_exists('exists', $this->fields[$index])) {
108+
return $this->fields[$index]['exists'];
109+
}
106110
}
107111
return false;
108112
}
@@ -117,7 +121,9 @@ public function existsByPath(string $path): bool
117121
{
118122
foreach ($this->fields as $field) {
119123
if ($field['path'] == $path) {
120-
return $field['exists'];
124+
if (array_key_exists('exists', $field)) {
125+
return $field['exists'];
126+
}
121127
}
122128
}
123129
return false;
@@ -132,7 +138,9 @@ public function existsByPath(string $path): bool
132138
public function path(int $index): ?string
133139
{
134140
if (array_key_exists($index, $this->fields)) {
135-
return $this->fields[$index]['path'];
141+
if (array_key_exists('path', $this->fields[$index])) {
142+
return $this->fields[$index]['path'];
143+
}
136144
}
137145
return null;
138146
}

Couchbase/Management/BucketManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use Couchbase\Extension;
2424

25-
class BucketManager
25+
class BucketManager implements BucketManagerInterface
2626
{
2727
/**
2828
* @var resource
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Couchbase\Management;
4+
5+
interface BucketManagerInterface
6+
{
7+
public function createBucket(BucketSettings $settings, CreateBucketOptions $options = null);
8+
9+
public function updateBucket(BucketSettings $settings, UpdateBucketOptions $options = null);
10+
11+
public function dropBucket(string $name, DropBucketOptions $options = null);
12+
13+
public function getBucket(string $name, GetBucketOptions $options = null): BucketSettings;
14+
15+
public function getAllBuckets(GetAllBucketsOptions $options = null): array;
16+
17+
public function flush(string $name, FlushBucketOptions $options = null);
18+
}

Couchbase/Management/CollectionManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Couchbase\Exception\InvalidArgumentException;
2424
use Couchbase\Extension;
2525

26-
class CollectionManager
26+
class CollectionManager implements CollectionManagerInterface
2727
{
2828
/**
2929
* @var resource
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Couchbase\Management;
4+
5+
interface CollectionManagerInterface
6+
{
7+
public function getAllScopes(GetAllScopesOptions $options = null): array;
8+
9+
public function createScope(string $name, CreateScopeOptions $options = null);
10+
11+
public function dropScope(string $name, DropScopeOptions $options = null);
12+
13+
public function createCollection($scopeName, $collectionName = null, $settings = null, $options = null);
14+
15+
public function dropCollection($scopeName, $collectionName = null, $options = null);
16+
17+
public function updateCollection(string $scopeName, string $collectionName, UpdateCollectionSettings $settings, UpdateCollectionOptions $options = null);
18+
}

Couchbase/Management/CollectionQueryIndexManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use Couchbase\Exception\UnambiguousTimeoutException;
2323
use Couchbase\Extension;
2424

25-
class CollectionQueryIndexManager
25+
class CollectionQueryIndexManager implements CollectionQueryIndexManagerInterface
2626
{
2727
private string $collectionName;
2828
private string $scopeName;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Couchbase\Management;
4+
5+
interface CollectionQueryIndexManagerInterface
6+
{
7+
public function getAllIndexes(GetAllQueryIndexesOptions $options = null): array;
8+
9+
public function createIndex(string $indexName, array $fields, CreateQueryIndexOptions $options = null);
10+
11+
public function createPrimaryIndex(CreateQueryPrimaryIndexOptions $options = null);
12+
13+
public function dropIndex(string $indexName, DropQueryIndexOptions $options = null);
14+
15+
public function dropPrimaryIndex(DropQueryPrimaryIndexOptions $options = null);
16+
17+
public function buildDeferredIndexes(BuildQueryIndexesOptions $options = null);
18+
19+
public function watchIndexes(array $indexNames, int $timeoutMilliseconds, WatchQueryIndexesOptions $options = null);
20+
}

Couchbase/Management/QueryIndexManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Couchbase\Exception\UnambiguousTimeoutException;
2424
use Couchbase\Extension;
2525

26-
class QueryIndexManager
26+
class QueryIndexManager implements QueryIndexManagerInterface
2727
{
2828
/**
2929
* @var resource
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Couchbase\Management;
4+
5+
interface QueryIndexManagerInterface
6+
{
7+
public function getAllIndexes(string $bucketName, GetAllQueryIndexesOptions $options = null): array;
8+
9+
public function createIndex(string $bucketName, string $indexName, array $fields, CreateQueryIndexOptions $options = null);
10+
11+
public function createPrimaryIndex(string $bucketName, CreateQueryPrimaryIndexOptions $options = null);
12+
13+
public function dropIndex(string $bucketName, string $indexName, DropQueryIndexOptions $options = null);
14+
15+
public function dropPrimaryIndex(string $bucketName, DropQueryPrimaryIndexOptions $options = null);
16+
17+
public function buildDeferredIndexes(string $bucketName, BuildQueryIndexesOptions $options = null);
18+
19+
public function watchIndexes(string $bucketName, array $indexNames, int $timeoutMilliseconds, WatchQueryIndexesOptions $options = null);
20+
}

Couchbase/Management/SearchIndexManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use Couchbase\Extension;
2424

25-
class SearchIndexManager
25+
class SearchIndexManager implements SearchIndexManagerInterface
2626
{
2727
/**
2828
* @var resource

0 commit comments

Comments
 (0)