forked from php-db/phpdb-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriverInterfaceFactoryFactory.php
More file actions
34 lines (28 loc) · 1.14 KB
/
DriverInterfaceFactoryFactory.php
File metadata and controls
34 lines (28 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
declare(strict_types=1);
namespace PhpDb\Adapter\Sqlite\Container;
use PhpDb\Container\AdapterManager;
use PhpDb\Container\DriverInterfaceFactoryFactoryInterface as FactoryFactoryInterface;
use Psr\Container\ContainerInterface;
use RuntimeException;
use function sprintf;
final class DriverInterfaceFactoryFactory implements FactoryFactoryInterface
{
public function __invoke(
?ContainerInterface $container = null,
?string $requestedName = null
): callable {
$adapterConfig = $container->get('config')['db']['adapters'] ?? [];
if (! isset($adapterConfig[$requestedName]['driver'])) {
throw new RuntimeException(sprintf(
'Named adapter "%s" is not configured with a driver',
$requestedName
));
}
$adapterServices = $container->get('config')[AdapterManager::class];
$configuredDriver = $adapterConfig[$requestedName]['driver'];
$aliasTo ??= $adapterServices['aliases'][$configuredDriver] ?? $configuredDriver;
$driverFactory = $adapterServices['factories'][$aliasTo];
return new $driverFactory();
}
}