| 1 | <?php |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Register an SQL database connection with the service container. |
||
| 18 | * |
||
| 19 | * @param Container $container |
||
| 20 | */ |
||
| 21 | public function register(Container $container) |
||
| 22 | { |
||
| 23 | $container->register(array( |
||
| 24 | 'Darya\Database\Connection' => function ($container) { |
||
| 25 | $config = $container->config; |
||
| 26 | |||
| 27 | $factory = new Factory; |
||
| 28 | |||
| 29 | $connection = $factory->create($config['database.type'], array( |
||
| 30 | 'hostname' => $config['database.hostname'], |
||
| 31 | 'username' => $config['database.username'], |
||
| 32 | 'password' => $config['database.password'], |
||
| 33 | 'database' => $config['database.database'] |
||
| 34 | )); |
||
| 35 | |||
| 36 | $connection->setEventDispatcher($container->event); |
||
| 37 | |||
| 43 |