Completed
Push — master ( 588b6d...1f8c3f )
by Park Jong-Hun
03:16
created

DatabaseManager::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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