File tree Expand file tree Collapse file tree 3 files changed +19
-25
lines changed
Expand file tree Collapse file tree 3 files changed +19
-25
lines changed Original file line number Diff line number Diff line change 11<?php declare (strict_types=1 );
22
33use App \Foundation \Factory \LoggerFactory ;
4+ use Doctrine \DBAL \Configuration as DoctrineConfiguration ;
5+ use Doctrine \DBAL \Connection ;
6+ use Doctrine \DBAL \DriverManager ;
47use Psr \Container \ContainerInterface ;
58use Selective \BasePath \BasePathMiddleware ;
69use Slim \App ;
97100 return $ container ->get (Session::class);
98101};
99102
103+ // Database
104+ $ object [Connection::class] = function (ContainerInterface $ container ) {
105+ $ config = new DoctrineConfiguration ();
106+ $ connectionParams = $ container ->get ('settings ' )['db ' ];
107+
108+ return DriverManager::getConnection ($ connectionParams , $ config );
109+ };
110+
111+ $ object [PDO ::class] = function (ContainerInterface $ container ) {
112+ return $ container ->get (Connection::class)->getWrappedConnection ();
113+ };
114+
100115return $ objects ;
Original file line number Diff line number Diff line change 11<?php declare (strict_types=1 );
22
3- $ db = [];
4-
5- $ db ['connections ' ] = [];
6-
7- $ db ['connections ' ]['mysql ' ] = [
3+ $ connection = [
84 'driver ' => 'pdo_mysql ' ,
95 'host ' => 'localhost ' ,
106 'port ' => 3306 ,
2218 ],
2319];
2420
25- // Grab connections from environment config
26- $ connections = appEnv ('db ' , []);
27-
28- // Add connections to array.
29- foreach ($ connections as $ name => $ config ) {
30- $ db ['connections ' ][$ name ] = $ config ;
31- }
32-
33- return $ db ;
21+ return appEnv ('db ' , $ connection );
Original file line number Diff line number Diff line change 88// App Environment
99$ _ENV ['app.environment ' ] = 'production ' ;
1010
11- // Database Connections
12- $ _ENV ['db ' ] = [];
13-
14- // mysql connection example
15- $ _ENV ['db ' ]['mysql ' ] = [
11+ // Database Connection example
12+ $ _ENV ['db ' ] = [
1613 'driver ' => 'pdo_mysql ' ,
1714 'host ' => 'localhost ' ,
1815 'port ' => 3306 ,
2926 PDO ::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci ' ,
3027 ],
3128];
32-
33- // sqlite connection example
34- $ _ENV ['db ' ]['sqlite ' ] = [
35- 'driver ' => 'pdo_sqlite ' ,
36- 'url ' => 'sqlite:/// ' . __DIR__ . '/storage/database/app.sqlite ' ,
37- ];
You can’t perform that action at this time.
0 commit comments