Completed
Push — 1.x ( 0b668e...1b7ebe )
by Yuu
01:46
created

EntityManagerProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 3
c 3
b 1
f 0
lcom 1
cbo 3
dl 0
loc 52
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setSqlLogger() 0 4 1
A get() 0 7 1
1
<?php
2
/**
3
 * This file is part of the Ray.DoctrineOrmModule package
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\DoctrineOrmModule;
8
9
use Doctrine\DBAL\Logging\SQLLogger;
10
use Doctrine\ORM\EntityManager;
11
use Doctrine\ORM\EntityManagerInterface;
12
use Doctrine\ORM\Tools\Setup;
13
use Ray\Di\Di\Inject;
14
use Ray\Di\ProviderInterface;
15
use Ray\DoctrineOrmModule\Annotation\EntityManagerConfig;
16
17
class EntityManagerProvider implements ProviderInterface
18
{
19
    /**
20
     * @var array
21
     */
22
    private $params;
23
24
    /**
25
     * @var array
26
     */
27
    private $paths;
28
29
    /**
30
     * @var SQLLogger
31
     */
32
    private $logger;
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param array $config
38
     *
39
     * @EntityManagerConfig
40
     */
41 10
    public function __construct(array $config)
42
    {
43 10
        list($this->params, $this->paths) = $config;
44 10
    }
45
46
    /**
47
     * @param SQLLogger $logger
48
     *
49
     * @Inject(optional=true)
50
     */
51 2
    public function setSqlLogger(SQLLogger $logger)
52
    {
53 2
        $this->logger = $logger;
54 2
    }
55
56
    /**
57
     * {@inheritdoc}
58
     *
59
     * @return EntityManagerInterface
60
     */
61 10
    public function get()
62
    {
63 10
        $config = Setup::createAnnotationMetadataConfiguration($this->paths);
64 10
        $config->setSQLLogger($this->logger);
65
66 10
        return EntityManager::create($this->params, $config);
67
    }
68
}
69