Completed
Push — master ( 5dd1c9...fbf102 )
by Chris
02:42
created

DatabaseConnectionService   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 21 1
1
<?php
2
namespace Darya\Service\Provider;
3
4
use Darya\Database\Factory;
5
use Darya\Service\Contracts\Container;
6
use Darya\Service\Contracts\Provider;
7
8
/**
9
 * A service provider that provides a MySQL connection using the configuration
10
 * registered with the service container.
11
 * 
12
 * @author Chris Andrew <[email protected]>
13
 */
14
class DatabaseConnectionService implements Provider
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
				
38
				return $connection;
39
			}
40
		));
41
	}
42
}
43