Skip to content

Merge v1.x into v2.x #1518

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 1 commit into from
Nov 4, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function __debugInfo()
*/
public function __get(string $databaseName)
{
return $this->selectDatabase($databaseName);
return $this->getDatabase($databaseName);
}

/**
Expand Down Expand Up @@ -247,6 +247,37 @@ public function dropDatabase(string $databaseName, array $options = [])
return $operation->execute($server);
}

/**
* Returns a collection instance.
*
* If the collection does not exist in the database, it is not created when
* invoking this method.
*
* @see Collection::__construct() for supported options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
public function getCollection(string $databaseName, string $collectionName, array $options = []): Collection
{
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];

return new Collection($this->manager, $databaseName, $collectionName, $options);
}

/**
* Returns a database instance.
*
* If the database does not exist on the server, it is not created when
* invoking this method.
*
* @see Database::__construct() for supported options
*/
public function getDatabase(string $databaseName, array $options = []): Database
{
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];

return new Database($this->manager, $databaseName, $options);
}

/**
* Return the Manager.
*
Expand Down Expand Up @@ -354,9 +385,7 @@ final public function removeSubscriber(Subscriber $subscriber): void
*/
public function selectCollection(string $databaseName, string $collectionName, array $options = [])
{
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];

return new Collection($this->manager, $databaseName, $collectionName, $options);
return $this->getCollection($databaseName, $collectionName, $options);
}

/**
Expand All @@ -370,9 +399,7 @@ public function selectCollection(string $databaseName, string $collectionName, a
*/
public function selectDatabase(string $databaseName, array $options = [])
{
$options += ['typeMap' => $this->typeMap, 'builderEncoder' => $this->builderEncoder];

return new Database($this->manager, $databaseName, $options);
return $this->getDatabase($databaseName, $options);
}

/**
Expand Down
34 changes: 24 additions & 10 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public function __debugInfo()
*/
public function __get(string $collectionName)
{
return $this->selectCollection($collectionName);
return $this->getCollection($collectionName);
}

/**
Expand Down Expand Up @@ -422,6 +422,28 @@ public function dropCollection(string $collectionName, array $options = [])
return $operation->execute($server);
}

/**
* Returns a collection instance.
*
* If the collection does not exist in the database, it is not created when
* invoking this method.
*
* @see Collection::__construct() for supported options
* @throws InvalidArgumentException for parameter/option parsing errors
*/
public function getCollection(string $collectionName, array $options = []): Collection
{
$options += [
'builderEncoder' => $this->builderEncoder,
'readConcern' => $this->readConcern,
'readPreference' => $this->readPreference,
'typeMap' => $this->typeMap,
'writeConcern' => $this->writeConcern,
];

return new Collection($this->manager, $this->databaseName, $collectionName, $options);
}

/**
* Returns the database name.
*
Expand Down Expand Up @@ -588,15 +610,7 @@ public function renameCollection(string $fromCollectionName, string $toCollectio
*/
public function selectCollection(string $collectionName, array $options = [])
{
$options += [
'builderEncoder' => $this->builderEncoder,
'readConcern' => $this->readConcern,
'readPreference' => $this->readPreference,
'typeMap' => $this->typeMap,
'writeConcern' => $this->writeConcern,
];

return new Collection($this->manager, $this->databaseName, $collectionName, $options);
return $this->getCollection($collectionName, $options);
}

/**
Expand Down