Completed
Push — master ( 7a1429...168b0d )
by Chris
02:39
created

MySqlService::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 1
eloc 11
nc 1
nop 1
1
<?php
2
namespace Darya\Service\Provider;
3
4
use Darya\Database\Connection\MySql;
5
use Darya\Database\Factory;
6
use Darya\Service\Contracts\Container;
7
use Darya\Service\Contracts\Provider;
8
9
/**
10
 * A service provider that provides a MySQL connection using the configuration
11
 * registered with the service container.
12
 * 
13
 * @author Chris Andrew <[email protected]>
14
 */
15
class MySqlService implements Provider
16
{
17
    public function register(Container $container)
18
    {
19
        $container->register(array(
20
            'Darya\Database\Connection' => function ($container) {
21
                $config = $container->config;
22
                
23
                $connection = new MySql(
24
                    $config['database.hostname'],
25
                    $config['database.username'],
26
                    $config['database.password'],
27
                    $config['database.database']
28
                );
29
                
30
                $connection->setEventDispatcher($container->event);
31
                
32
                return $connection;
33
            }
34
        ));
35
    }
36
}
37