Skip to content

PCBC-960 Merge protostellar branch to master #138

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

Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "src/deps/couchbase-cxx-client"]
path = src/deps/couchbase-cxx-client
url = https://github.com/couchbaselabs/couchbase-cxx-client.git
[submodule "src/deps/protostellar"]
path = src/deps/protostellar
url = https://github.com/couchbase/protostellar
30 changes: 30 additions & 0 deletions Couchbase/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class Cluster implements ClusterInterface
*/
public function __construct(string $connectionString, ClusterOptions $options)
{
if (
preg_match("/^protostellar:\/\//", $connectionString) ||
preg_match("/^couchbase2:\/\//", $connectionString)
) {
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());
$this->options = $options;
Expand All @@ -67,9 +73,33 @@ public static function connect(string $connectionString, ClusterOptions $options
if (preg_match("/^couchbases?:\/\//", $connectionString)) {
return new Cluster($connectionString, $options);
}

if (
preg_match("/^protostellar:\/\//", $connectionString) ||
preg_match("/^couchbase2:\/\//", $connectionString)
) {
Cluster::enableProtostellar();
}
return ClusterRegistry::connect($connectionString, $options);
}

private static function enableProtostellar(): void
{
ClusterRegistry::registerConnectionHandler(
"/^protostellar:\/\//",
function (string $connectionString, ClusterOptions $options) {
return new Protostellar\Cluster($connectionString, $options);
}
);

ClusterRegistry::registerConnectionHandler(
"/^couchbase2:\/\//",
function (string $connectionString, ClusterOptions $options) {
return new Protostellar\Cluster($connectionString, $options);
}
);
}

/**
* Returns a new bucket object.
*
Expand Down
8 changes: 4 additions & 4 deletions Couchbase/Datastructures/CouchbaseList.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use ArrayAccess;
use ArrayIterator;
use Couchbase\Collection;
use Couchbase\CollectionInterface;
use Couchbase\Exception\DocumentNotFoundException;
use Couchbase\Exception\InvalidArgumentException;
use Couchbase\Exception\PathMismatchException;
Expand All @@ -48,19 +48,19 @@
class CouchbaseList implements Countable, IteratorAggregate, ArrayAccess
{
private string $id;
private Collection $collection;
private CollectionInterface $collection;
private Options\CouchbaseList $options;

/**
* CouchbaseList constructor.
*
* @param string $id identifier of the backing document.
* @param Collection $collection collection instance, where the document will be stored
* @param CollectionInterface $collection collection instance, where the document will be stored
* @param Options\CouchbaseList|null $options
*
* @since 4.0.0
*/
public function __construct(string $id, Collection $collection, ?Options\CouchbaseList $options = null)
public function __construct(string $id, CollectionInterface $collection, ?Options\CouchbaseList $options = null)
{
$this->id = $id;
$this->collection = $collection;
Expand Down
8 changes: 4 additions & 4 deletions Couchbase/Datastructures/CouchbaseMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use ArrayAccess;
use ArrayIterator;
use Couchbase\Collection;
use Couchbase\CollectionInterface;
use Couchbase\Exception\DocumentNotFoundException;
use Couchbase\Exception\InvalidArgumentException;
use Couchbase\Exception\PathMismatchException;
Expand All @@ -44,19 +44,19 @@
class CouchbaseMap implements Countable, IteratorAggregate, ArrayAccess
{
private string $id;
private Collection $collection;
private CollectionInterface $collection;
private Options\CouchbaseMap $options;

/**
* CouchbaseList constructor.
*
* @param string $id identifier of the backing document.
* @param Collection $collection collection instance, where the document will be stored
* @param CollectionInterface $collection collection instance, where the document will be stored
* @param Options\CouchbaseMap|null $options
*
* @since 4.0.0
*/
public function __construct(string $id, Collection $collection, ?Options\CouchbaseMap $options = null)
public function __construct(string $id, CollectionInterface $collection, ?Options\CouchbaseMap $options = null)
{
$this->id = $id;
$this->collection = $collection;
Expand Down
8 changes: 4 additions & 4 deletions Couchbase/Datastructures/CouchbaseQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace Couchbase\Datastructures;

use ArrayIterator;
use Couchbase\Collection;
use Couchbase\CollectionInterface;
use Couchbase\Exception\DocumentNotFoundException;
use Couchbase\Exception\InvalidArgumentException;
use Couchbase\Exception\PathNotFoundException;
Expand All @@ -41,19 +41,19 @@
class CouchbaseQueue implements Countable, IteratorAggregate
{
private string $id;
private Collection $collection;
private CollectionInterface $collection;
private Options\CouchbaseQueue $options;

/**
* CouchbaseQueue constructor.
*
* @param string $id identifier of the backing document.
* @param Collection $collection collection instance, where the document will be stored
* @param CollectionInterface $collection collection instance, where the document will be stored
* @param Options\CouchbaseQueue|null $options
*
* @since 4.0.0
*/
public function __construct(string $id, Collection $collection, ?Options\CouchbaseQueue $options = null)
public function __construct(string $id, CollectionInterface $collection, ?Options\CouchbaseQueue $options = null)
{
$this->id = $id;
$this->collection = $collection;
Expand Down
8 changes: 4 additions & 4 deletions Couchbase/Datastructures/CouchbaseSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace Couchbase\Datastructures;

use ArrayIterator;
use Couchbase\Collection;
use Couchbase\CollectionInterface;
use Couchbase\Exception\DocumentNotFoundException;
use Couchbase\Exception\InvalidArgumentException;
use Couchbase\Exception\PathExistsException;
Expand All @@ -40,17 +40,17 @@
class CouchbaseSet implements Countable, IteratorAggregate
{
private string $id;
private Collection $collection;
private CollectionInterface $collection;
private Options\CouchbaseSet $options;

/**
* CouchbaseSet constructor.
*
* @param string $id identifier of the backing document.
* @param Collection $collection collection instance, where the document will be stored
* @param CollectionInterface $collection collection instance, where the document will be stored
* @param Options\CouchbaseSet|null $options
*/
public function __construct(string $id, Collection $collection, ?Options\CouchbaseSet $options = null)
public function __construct(string $id, CollectionInterface $collection, ?Options\CouchbaseSet $options = null)
{
$this->id = $id;
$this->collection = $collection;
Expand Down
25 changes: 25 additions & 0 deletions Couchbase/Exception/PermissionDeniedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* Copyright 2014-Present Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace Couchbase\Exception;

class PermissionDeniedException extends CouchbaseException
{
}
22 changes: 15 additions & 7 deletions Couchbase/LookupInResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ public function content(int $index)
public function contentByPath(string $path)
{
foreach ($this->fields as $field) {
if ($field['path'] == $path) {
if (!array_key_exists('exists', $field) || !$field['exists']) {
throw new PathNotFoundException(sprintf("LookupIn path is not found for path: %s", $path));
if (array_key_exists('path', $field)) {
if ($field['path'] == $path) {
if (!array_key_exists('exists', $field) || !$field['exists']) {
throw new PathNotFoundException(sprintf("LookupIn path is not found for path: %s", $path));
}
return $this->transcoder->decode($field['value'], 0);
}
return $this->transcoder->decode($field['value'], 0);
}
}
throw new OutOfBoundsException(sprintf("LookupIn result does not have entry for path: %s", $path));
Expand All @@ -102,7 +104,9 @@ public function contentByPath(string $path)
public function exists(int $index): bool
{
if (array_key_exists($index, $this->fields)) {
return $this->fields[$index]['exists'];
if (array_key_exists('exists', $this->fields[$index])) {
return $this->fields[$index]['exists'];
}
}
return false;
}
Expand All @@ -117,7 +121,9 @@ public function existsByPath(string $path): bool
{
foreach ($this->fields as $field) {
if ($field['path'] == $path) {
return $field['exists'];
if (array_key_exists('exists', $field)) {
return $field['exists'];
}
}
}
return false;
Expand All @@ -132,7 +138,9 @@ public function existsByPath(string $path): bool
public function path(int $index): ?string
{
if (array_key_exists($index, $this->fields)) {
return $this->fields[$index]['path'];
if (array_key_exists('path', $this->fields[$index])) {
return $this->fields[$index]['path'];
}
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Couchbase/Management/BucketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use Couchbase\Extension;

class BucketManager
class BucketManager implements BucketManagerInterface
{
/**
* @var resource
Expand Down
18 changes: 18 additions & 0 deletions Couchbase/Management/BucketManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Couchbase\Management;

interface BucketManagerInterface
{
public function createBucket(BucketSettings $settings, CreateBucketOptions $options = null);

public function updateBucket(BucketSettings $settings, UpdateBucketOptions $options = null);

public function dropBucket(string $name, DropBucketOptions $options = null);

public function getBucket(string $name, GetBucketOptions $options = null): BucketSettings;

public function getAllBuckets(GetAllBucketsOptions $options = null): array;

public function flush(string $name, FlushBucketOptions $options = null);
}
2 changes: 1 addition & 1 deletion Couchbase/Management/CollectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Couchbase\Exception\InvalidArgumentException;
use Couchbase\Extension;

class CollectionManager
class CollectionManager implements CollectionManagerInterface
{
/**
* @var resource
Expand Down
18 changes: 18 additions & 0 deletions Couchbase/Management/CollectionManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Couchbase\Management;

interface CollectionManagerInterface
{
public function getAllScopes(GetAllScopesOptions $options = null): array;

public function createScope(string $name, CreateScopeOptions $options = null);

public function dropScope(string $name, DropScopeOptions $options = null);

public function createCollection($scopeName, $collectionName = null, $settings = null, $options = null);

public function dropCollection($scopeName, $collectionName = null, $options = null);

public function updateCollection(string $scopeName, string $collectionName, UpdateCollectionSettings $settings, UpdateCollectionOptions $options = null);
}
2 changes: 1 addition & 1 deletion Couchbase/Management/CollectionQueryIndexManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Couchbase\Exception\UnambiguousTimeoutException;
use Couchbase\Extension;

class CollectionQueryIndexManager
class CollectionQueryIndexManager implements CollectionQueryIndexManagerInterface
{
private string $collectionName;
private string $scopeName;
Expand Down
20 changes: 20 additions & 0 deletions Couchbase/Management/CollectionQueryIndexManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Couchbase\Management;

interface CollectionQueryIndexManagerInterface
{
public function getAllIndexes(GetAllQueryIndexesOptions $options = null): array;

public function createIndex(string $indexName, array $fields, CreateQueryIndexOptions $options = null);

public function createPrimaryIndex(CreateQueryPrimaryIndexOptions $options = null);

public function dropIndex(string $indexName, DropQueryIndexOptions $options = null);

public function dropPrimaryIndex(DropQueryPrimaryIndexOptions $options = null);

public function buildDeferredIndexes(BuildQueryIndexesOptions $options = null);

public function watchIndexes(array $indexNames, int $timeoutMilliseconds, WatchQueryIndexesOptions $options = null);
}
2 changes: 1 addition & 1 deletion Couchbase/Management/QueryIndexManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Couchbase\Exception\UnambiguousTimeoutException;
use Couchbase\Extension;

class QueryIndexManager
class QueryIndexManager implements QueryIndexManagerInterface
{
/**
* @var resource
Expand Down
20 changes: 20 additions & 0 deletions Couchbase/Management/QueryIndexManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Couchbase\Management;

interface QueryIndexManagerInterface
{
public function getAllIndexes(string $bucketName, GetAllQueryIndexesOptions $options = null): array;

public function createIndex(string $bucketName, string $indexName, array $fields, CreateQueryIndexOptions $options = null);

public function createPrimaryIndex(string $bucketName, CreateQueryPrimaryIndexOptions $options = null);

public function dropIndex(string $bucketName, string $indexName, DropQueryIndexOptions $options = null);

public function dropPrimaryIndex(string $bucketName, DropQueryPrimaryIndexOptions $options = null);

public function buildDeferredIndexes(string $bucketName, BuildQueryIndexesOptions $options = null);

public function watchIndexes(string $bucketName, array $indexNames, int $timeoutMilliseconds, WatchQueryIndexesOptions $options = null);
}
2 changes: 1 addition & 1 deletion Couchbase/Management/SearchIndexManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use Couchbase\Extension;

class SearchIndexManager
class SearchIndexManager implements SearchIndexManagerInterface
{
/**
* @var resource
Expand Down
Loading