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

EntityManagerFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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