Completed
Push — master ( c2bacd...81a0c2 )
by Park Jong-Hun
08:02
created

DatabaseManager::setConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Core;
4
5
use Doctrine\ORM\Tools\Setup;
6
use Doctrine\ORM\EntityManager;
7
8
class DatabaseManager
9
{
10
11
    private $config = [];
12
13
    private function __construct()
14
    {
15
    }
16
17
    /**
18
     * @return self
19
     */
20
    public static function getInstance()
21
    {
22
        static $instance = null;
23
24
        if ($instance === null) {
25
            $instance = new self();
26
        }
27
28
        return $instance;
29
    }
30
31
    public function setConfig(array $config)
32
    {
33
        $this->config = $config;
34
    }
35
36
    /**
37
     * @return EntityManager
38
     */
39
    public function getEntityManager()
40
    {
41
        $config = Setup::createAnnotationMetadataConfiguration(
42
                    $this->config['entityPath'],
43
                    $this->config['devMode']
44
                    );
45
        return EntityManager::create($this->config['connections'][$this->config['defaultConnection']], $config);
46
    }
47
}
48