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

DatabaseStorageService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 13 1
A boot() 0 4 1
1
<?php
2
namespace Darya\Service\Provider;
3
4
use Darya\Database\Storage;
5
use Darya\Service\Contracts\Container;
6
use Darya\Service\Contracts\Provider;
7
use Darya\ORM\Record;
8
9
/**
10
 * A service provider that provides a database storage implementation using
11
 * whatever database connection is registered with the service container.
12
 * 
13
 * Registers the provided database storage with Darya's active record class.
14
 * 
15
 * @author Chris Andrew <[email protected]>
16
 */
17
class DatabaseStorageService implements Provider
18
{
19
    public function register(Container $container)
20
    {
21
        $container->register(array(
22
            'Darya\Database\Storage' => function ($container) {
23
                return new Storage($container->resolve('Darya\Database\Connection'));
24
            },
25
            'Darya\Storage\Readable'   => 'Darya\Database\Storage',
26
            'Darya\Storage\Modifiable' => 'Darya\Database\Storage',
27
            'Darya\Storage\Searchable' => 'Darya\Database\Storage',
28
            'Darya\Storage\Queryable'  => 'Darya\Database\Storage',
29
            'Darya\Storage\Aggregational' => 'Darya\Database\Storage'
30
        ));
31
    }
32
    
33
    public function boot(Storage $storage)
34
    {
35
        Record::setSharedStorage($storage);
36
    }
37
}
38