Completed
Push — master ( 9e2a7d...173c6d )
by Jared
06:54 queued 03:34
created

ModelDriver::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
dl 0
loc 18
rs 9.4285
c 2
b 0
f 2
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
/**
4
 * @author Jared King <[email protected]>
5
 *
6
 * @see http://jaredtking.com
7
 *
8
 * @copyright 2015 Jared King
9
 * @license MIT
10
 */
11
12
namespace Pulsar\Services;
13
14
use Pulsar\Driver\DatabaseDriver;
15
use Pulsar\Model;
16
use Pulsar\Validator;
17
18
/**
19
 * Class ModelDriver.
20
 */
21
class ModelDriver
22
{
23
    /**
24
     * @var \Pulsar\Driver\DriverInterface
25
     */
26
    private $driver;
27
28
    public function __construct($app)
29
    {
30
        // set up the model driver
31
        $config = $app['config'];
32
        $class = $config->get('models.driver');
33
        $this->driver = new $class();
34
35
        if ($this->driver instanceof DatabaseDriver) {
36
            if (isset($app['database'])) {
37
                $this->driver->setConnectionManager($app['database']);
38
            }
39
        }
40
41
        Model::setDriver($this->driver);
42
43
        // pass optional configuration to model validator
44
        Validator::configure($config->get('models.validator'));
45
    }
46
47
    public function __invoke()
48
    {
49
        return $this->driver;
50
    }
51
}
52