HydratorBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Query\Hydrator;
4
5
use Doctrine\Bundle\DoctrineBundle\Registry;
6
use Doctrine\ORM\EntityManager;
7
use Mdiyakov\DoctrineSolrBundle\Config\Config;
8
9
class HydratorBuilder
10
{
11
    /**
12
     * @var Registry
13
     */
14
    private $registry;
15
16
    /**
17
     * @var Config
18
     */
19
    private $config;
20
21
    /**
22
     * @param Registry $registry
23
     * @param Config $config
24
     */
25
    public function __construct(Registry $registry, Config $config)
26
    {
27
        $this->registry = $registry;
28
        $this->config = $config;
29
    }
30
31
    /**
32
     * @param string $entityClass
33
     * @return SelectQueryHydrator
34
     * @throws \LogicException
35
     */
36
    public function buildSelectQueryHydratorByClass($entityClass)
37
    {
38
        $em = $this->registry->getManagerForClass($entityClass);
39
        if (!$em instanceof EntityManager) {
40
            throw new \LogicException(
41
                'EntityManager must be instance of \Doctrine\ORM\EntityManager'
42
            );
43
        }
44
45
        return new SelectQueryHydrator(
46
            $em->getRepository($entityClass),
47
            $this->config->getSchemaByEntityClass($entityClass),
48
            $this->config->getEntityConfig($entityClass)
49
        );
50
    }
51
52
}