Completed
Push — master ( a40390...c25130 )
by
11s
created

Manager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 41
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A persist() 0 3 1
A flush() 0 3 1
A getRepository() 0 3 1
A get() 0 14 2
1
<?php
2
3
namespace LineMob\Core\Mocky\Doctrine;
4
5
use Doctrine\ORM\Tools\Setup;
6
use Doctrine\ORM\EntityManager;
7
8
class Manager
9
{
10
    /**
11
     * @var EntityManager
12
     */
13
    static private $manager;
14
15
    public static function get($isDevMode = true)
16
    {
17
        if (self::$manager) {
18
            return self::$manager;
19
        }
20
21
        $ds = DIRECTORY_SEPARATOR;
22
        $config = Setup::createAnnotationMetadataConfiguration([__DIR__.$ds.'Model'], $isDevMode);
23
        $conn = array(
24
            'driver' => 'pdo_sqlite',
25
            'path' => __DIR__.$ds.'db.sqlite',
26
        );
27
28
        return self::$manager = EntityManager::create($conn, $config);
29
    }
30
31
    /**
32
     * @param $class
33
     *
34
     * @return \Doctrine\ORM\EntityRepository
35
     */
36
    public static function getRepository($class)
37
    {
38
        return self::get()->getRepository($class);
39
    }
40
41
    public static function persist($entity)
42
    {
43
        self::get()->persist($entity);
44
    }
45
46
    public static function flush($entity = null)
47
    {
48
        self::get()->flush($entity);
49
    }
50
}
51