Completed
Push — master ( 77abb4...5b1cd3 )
by Chris
02:37
created

DatabaseStorageService::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Darya\Foundation\Providers;
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
	/**
20
	 * Register a database storage implementation with the service container.
21
	 * 
22
	 * @param Container $container
23
	 */
24
	public function register(Container $container)
25
	{
26
		$container->register(array(
27
			'Darya\Database\Storage' => function ($container) {
28
				return new Storage($container->resolve('Darya\Database\Connection'));
29
			},
30
			'Darya\Storage\Readable'   => 'Darya\Database\Storage',
31
			'Darya\Storage\Modifiable' => 'Darya\Database\Storage',
32
			'Darya\Storage\Searchable' => 'Darya\Database\Storage',
33
			'Darya\Storage\Queryable'  => 'Darya\Database\Storage',
34
			'Darya\Storage\Aggregational' => 'Darya\Database\Storage'
35
		));
36
	}
37
	
38
	/**
39
	 * Attach the registered storage to the ORM's active record class.
40
	 * 
41
	 * @param Storage $storage
42
	 */
43
	public function boot(Storage $storage)
44
	{
45
		Record::setSharedStorage($storage);
46
	}
47
}
48