From 8a661dea9c6728f5d92ae17ec3bb30e4cb3a9a5f Mon Sep 17 00:00:00 2001 From: Andrey Voronin Date: Fri, 18 May 2018 01:50:00 +0300 Subject: [PATCH 1/2] Update CouchBase driver connection function with new couchbase PHP SDK 2.4, port and bucket passwords are no longer required as of CouchBase 5.0 --- docs/examples/couchbase.php | 2 -- src/phpFastCache/Drivers/Couchbase/Driver.php | 25 +++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/examples/couchbase.php b/docs/examples/couchbase.php index 4f356a740..ccacc1b3d 100644 --- a/docs/examples/couchbase.php +++ b/docs/examples/couchbase.php @@ -19,13 +19,11 @@ $InstanceCache = CacheManager::getInstance('couchbase', [ 'host' => 'your-couchbase-host', - 'port' => 8091, 'username' => 'your-couchbase-username', 'password' => 'your-couchbase-password', 'buckets' => [ [ 'bucket' => 'default', // The bucket name, generally "default" by default - 'password' => '' // The bucket password if there is ], ] ]); diff --git a/src/phpFastCache/Drivers/Couchbase/Driver.php b/src/phpFastCache/Drivers/Couchbase/Driver.php index 778325873..a7e09769d 100644 --- a/src/phpFastCache/Drivers/Couchbase/Driver.php +++ b/src/phpFastCache/Drivers/Couchbase/Driver.php @@ -143,23 +143,34 @@ protected function driverConnect() throw new phpFastCacheLogicException('Already connected to Couchbase server'); } else { - $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; - $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : 8091; - $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; - $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; + $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : NULL; + $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : NULL; + $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : NULL; $buckets = isset($this->config[ 'buckets' ]) ? $this->config[ 'buckets' ] : [ [ 'bucket' => 'default', - 'password' => '', ], ]; + + // Establish username and password for bucket access + $authenticator = new \Couchbase\PasswordAuthenticator(); + $authenticator->username($this->config[ 'username' ])->password($this->config[ 'password' ]); + + // Connect to Couchbase Server + if (isset($port)) { + $cluster = new CouchbaseClient("couchbase://" . $host . ":" . $port); + } else { + $cluster = new CouchbaseClient("couchbase://" . $host); + } - $this->instance = new CouchbaseClient("couchbase://{$host}:{$port}", $username, $password); + // Authenticate, then open buckets + $cluster->authenticate($authenticator); + $this->instance = $this->instance ?: $cluster; foreach ($buckets as $bucket) { $this->bucketCurrent = $this->bucketCurrent ?: $bucket[ 'bucket' ]; - $this->setBucket($bucket[ 'bucket' ], $this->instance->openBucket($bucket[ 'bucket' ], $bucket[ 'password' ])); + $this->setBucket($bucket[ 'bucket' ], $this->instance->openBucket($bucket[ 'bucket' ])); } } From d89275ec3332392e21b05585a07f0ccff5b4b708 Mon Sep 17 00:00:00 2001 From: Andrey Voronin Date: Fri, 18 May 2018 02:06:10 +0300 Subject: [PATCH 2/2] Fix minor Scrutinizer issues with unused variables --- src/phpFastCache/Drivers/Couchbase/Driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/phpFastCache/Drivers/Couchbase/Driver.php b/src/phpFastCache/Drivers/Couchbase/Driver.php index a7e09769d..611afabd5 100644 --- a/src/phpFastCache/Drivers/Couchbase/Driver.php +++ b/src/phpFastCache/Drivers/Couchbase/Driver.php @@ -155,7 +155,7 @@ protected function driverConnect() // Establish username and password for bucket access $authenticator = new \Couchbase\PasswordAuthenticator(); - $authenticator->username($this->config[ 'username' ])->password($this->config[ 'password' ]); + $authenticator->username($username)->password($password); // Connect to Couchbase Server if (isset($port)) {