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

EntityManagerProvider::setSqlLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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