Firestore database name customization is not impented.
Geolim4 opened this issue · 2 comments
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Is your feature request related to a problem? Please describe.
Currently, the php-sdk does not allow us to set a custom database name because it is hardcoded in the constructor (still in 1.39):
public function __construct(array $config = [])
{
$emulatorHost = getenv('FIRESTORE_EMULATOR_HOST');
$this->requireGrpc();
$config += [
'returnInt64AsObject' => false,
'scopes' => [self::FULL_CONTROL_SCOPE],
'database' => self::DEFAULT_DATABASE,
'hasEmulator' => (bool) $emulatorHost,
'emulatorHost' => $emulatorHost,
];
$this->database = $config['database'];
$this->connection = new Grpc($this->configureAuthentication($config) + [
'projectId' => $this->projectId,
]);
$this->valueMapper = new ValueMapper(
$this->connection,
$config['returnInt64AsObject']
);
}
Describe the solution you'd like
It would be nice to have the hability to change the database name, in case the administrator changed it in GCP:
The change is pretty simple:
public function __construct(array $config = [])
{
$emulatorHost = getenv('FIRESTORE_EMULATOR_HOST');
$this->requireGrpc();
$config += [
'returnInt64AsObject' => false,
'scopes' => [self::FULL_CONTROL_SCOPE],
'database' => $config['database'] ?? self::DEFAULT_DATABASE, // <========= This little change
'hasEmulator' => (bool) $emulatorHost,
'emulatorHost' => $emulatorHost,
];
$this->database = $config['database'];
$this->connection = new Grpc($this->configureAuthentication($config) + [
'projectId' => $this->projectId,
]);
$this->valueMapper = new ValueMapper(
$this->connection,
$config['returnInt64AsObject']
);
}
(plus Phpdoc updated obviously).
Describe alternatives you've considered
N/A
Additional context
Add any other context or screenshots about the feature request here.
@Geolim4 Hi there! Thanks for reporting this. So because the $config
variable is using +=
, this allows you to supply a database
parameter to override the default:
$config = ['database' => 'mydatabase'];
$config += ['database' => 'DEFAULT'];
var_dump($config);
// array(1) { ["database"]=>string(10) "mydatabase" }
So, the functionality you want already exists, we just don't have the parameter documented in PHPDoc.
Hello, for some reason when I passed it to the constructor the database stood on "(default)", I'll investigate this behavior on my side. Have a nice day !