File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55namespace PhpDb \Sqlite \Container ;
66
77use PhpDb \Adapter \AdapterInterface ;
8- use PhpDb \Adapter \SchemaAwareInterface ;
98use PhpDb \Metadata \MetadataInterface ;
109use PhpDb \Sqlite \Metadata ;
1110use Psr \Container \ContainerInterface ;
1211
1312final class MetadataInterfaceFactory
1413{
15- public function __invoke (ContainerInterface $ container ): MetadataInterface &Metadata \Source
16- {
17- /** @var AdapterInterface&SchemaAwareInterface $adapter */
18- $ adapter = $ container ->get (AdapterInterface::class);
14+ public const ADAPTER_SERVICE_NAME = 'adapter_service_name ' ;
15+ public function __invoke (
16+ ContainerInterface $ container ,
17+ string $ requestedName ,
18+ ?array $ options = null
19+ ): MetadataInterface &Metadata \Source {
20+ $ adapterServiceName = $ options [self ::ADAPTER_SERVICE_NAME ] ?? AdapterInterface::class;
1921
20- return new Metadata \Source (
21- $ adapter
22- );
22+ return new Metadata \Source ($ container ->get ($ adapterServiceName ));
2323 }
2424}
Original file line number Diff line number Diff line change 44
55namespace PhpDb \Sqlite \Container ;
66
7- use PhpDb \Adapter \AdapterInterface ;
8- use PhpDb \Adapter \Driver \ ConnectionInterface ;
7+ use PhpDb \Adapter \Driver \ PdoConnectionInterface ;
8+ use PhpDb \Adapter \Exception \ InvalidConnectionParametersException ;
99use PhpDb \Sqlite \Pdo \Connection ;
1010use Psr \Container \ContainerInterface ;
1111
1212final class PdoConnectionFactory
1313{
14- public function __invoke (ContainerInterface $ container ): ConnectionInterface &Connection
15- {
16- /** @var array $config */
17- $ config = $ container ->get ('config ' );
14+ public function __invoke (
15+ ContainerInterface $ container ,
16+ string $ requestedName ,
17+ ?array $ options = null
18+ ): PdoConnectionInterface &Connection {
19+ $ conn = $ options ['connection ' ] ?? [];
20+ if (! is_array ($ conn ) || $ conn === []) {
21+ throw new InvalidConnectionParametersException (
22+ 'Connection configuration must be an array of parameters passed via $options["connection"] ' ,
23+ $ conn
24+ );
25+ }
1826
19- /** @var array $dbConfig */
20- $ dbConfig = $ config [AdapterInterface::class] ?? [];
21-
22- /** @var array $connectionConfig */
23- $ connectionConfig = $ dbConfig ['connection ' ] ?? [];
24-
25- return new Connection ($ connectionConfig );
27+ return new Connection ($ conn );
2628 }
2729}
Original file line number Diff line number Diff line change @@ -19,18 +19,10 @@ public function __invoke(
1919 string $ requestedName ,
2020 ?array $ options = null
2121 ): PdoDriverInterface &Pdo \Driver {
22- // if (! $container->has('config')) {
23- // throw ContainerException::forService(
24- // Pdo\Driver::class,
25- // self::class,
26- // 'Container is missing config service'
27- // );
28- // }
29-
3022 /** @var Pdo\Connection $connectionInstance */
3123 $ connectionInstance = $ container ->build (
3224 Pdo \Connection::class,
33- [ ' connection ' => $ options[ ' connection ' ] ?? []]
25+ $ options
3426 );
3527
3628 /** @var ResultInterface&Result $resultInstance */
You can’t perform that action at this time.
0 commit comments