How to get bucket name from CouchbaseBucket object in PHP SDK?


#1

Hi,

We are finally upgrading our Couchbase SDK to the latest.

I used to get the bucket name from CouchbaseBucket by using reflection since $bucket->manager()->info() was not stable for some reason and it makes network request as far as I understand.

    $reflected = new ReflectionObject($this->bucket);
    $name = $reflected->getProperty('name');
    $name->setAccessible(true);
    $this->bucketName = $name->getValue($this->bucket);

How do I get bucket name from CouchbaseBucket object?


#2

There is no public API to get the name of the bucket, but as soon as it is not possible to change it for the bucket object, you can keep then in associative array where the name of the bucket would be the key.

In your example, why don’t you just initialize bucketName at the step where you open the bucket?

This is how it is done in Laravel connector:

This is how it is done in Yii2 connector:


#3

Well, I guess it’s another breaking change from Couchbase SDK.

SDK version 2.2.x had “getName” method as you see on https://github.com/couchbase/php-couchbase/blob/v2.2.4/php/src/CouchbaseBucket.class.php#L87

I really have no idea why a public API gets removed in a minor version update.

We are not using a framework specific library.

I can easily pass a new string value along with CouchbaseBucket object, but that just does not look right. It also requires a code change. It’s almost like passing a Person object with name variable in it, but then passing another string value for the name to a class. It’s simply unnecessary and error prone.


#4

@moon0326 you are welcome to review and test this change: http://review.couchbase.org/c/92167/


#5

I already wrapped my class to get bucketName method. It sounds like no one is using it anyway and…I don’t see the method in other SDK (node…or .net).