Completed
Pull Request — develop (#607)
by Tom
01:30
created

EntityManagerFactory::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
12
class EntityManagerFactory extends AbstractFactory
13
{
14
    /**
15
     * {@inheritDoc}
16
     *
17
     * @return EntityManager
18
     */
19
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
20
    {
21
        $options = $this->getOptions($container, 'entitymanager');
22
        $connection = $container->get($options->getConnection());
23
        $config     = $container->get($options->getConfiguration());
24
25
        // initializing the resolver
26
        // @todo should actually attach it to a fetched event manager here, and not
27
        //       rely on its factory code
28
        $container->get($options->getEntityResolver());
29
30
        return EntityManager::create($connection, $config);
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     *
36
     * @return EntityManager
37
     */
38
    public function createService(ContainerInterface $container)
39
    {
40
        return $this($container, EntityManager::class);
41
    }
42
43
    public function getOptionsClass() : string
44
    {
45
        return DoctrineORMModuleEntityManager::class;
46
    }
47
}
48