Completed
Push — master ( ddb2b2...d12e96 )
by Park Jong-Hun
03:09
created

DatabaseManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfig() 0 4 1
A getEntityManager() 0 10 2
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 static $config = [];
11
12
    public static function setConfig(array $config)
13
    {
14
        self::$config = $config;
15
    }
16
17
    /**
18
     * @return EntityManager
19
     */
20
    public static function getEntityManager($connectionName = null)
21
    {
22
        $connectionName = $connectionName ?: self::$config['defaultConnection'];
23
24
        $config = Setup::createAnnotationMetadataConfiguration(
25
            self::$config['entityPath'],
26
            self::$config['devMode']
27
        );
28
        return EntityManager::create(self::$config['connections'][$connectionName], $config);
29
    }
30
}
31