Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Allow to use any injection name if there is only 1 database #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/DatabaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public function __construct(DatabaseConfig $config, FactoryInterface $factory =
*/
public function createInjection(\ReflectionClass $class, string $context = null)
{
if (count($this->config->getDatabases()) === 1) {
return $this->database($this->config->getDefaultDatabase());
}

// if context is empty default database will be returned
return $this->database($context);
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Database/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public function testInjection(): void
$db = $container->get(Database::class);
$this->assertSame($read, $db->getDriver(Database::READ));
$this->assertSame($write, $db->getDriver(Database::WRITE));
$db = $container->get(Database::class, 'somecustomname');
$this->assertSame($read, $db->getDriver(Database::READ));
$this->assertSame($write, $db->getDriver(Database::WRITE));
}

public function testGetDrivers(): void
Expand Down