Completed
Pull Request — develop (#607)
by Tom
03:12 queued 01:40
created

EntityManagerFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 37
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 1
A createService() 0 4 1
A getOptionsClass() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineORMModule\Service;
6
7
use Doctrine\ORM\EntityManager;
8
use DoctrineModule\Service\AbstractFactory;
9
use DoctrineORMModule\Options\EntityManager as DoctrineORMModuleEntityManager;
10
use Interop\Container\ContainerInterface;
11
use function assert;
12
13
class EntityManagerFactory extends AbstractFactory
14
{
15
    /**
16
     * {@inheritDoc}
17
     *
18
     * @return EntityManager
19
     */
20
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
21
    {
22
        $options = $this->getOptions($container, 'entitymanager');
23
        assert($options instanceof DoctrineORMModuleEntityManager);
24
        $connection = $container->get($options->getConnection());
25
        $config     = $container->get($options->getConfiguration());
26
27
        // initializing the resolver
28
        // @todo should actually attach it to a fetched event manager here, and not
29
        //       rely on its factory code
30
        $container->get($options->getEntityResolver());
31
32
        return EntityManager::create($connection, $config);
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     *
38
     * @return EntityManager
39
     */
40
    public function createService(ContainerInterface $container)
41
    {
42
        return $this($container, EntityManager::class);
43
    }
44
45
    public function getOptionsClass() : string
46
    {
47
        return DoctrineORMModuleEntityManager::class;
48
    }
49
}
50