Completed
Push — master ( fbc42e...4f026e )
by Jonas
21:13
created

EntityManagerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 6
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 2
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * This file is part of SteamScore.
6
 *
7
 * (c) SteamScore <[email protected]>
8
 *
9
 * This Source Code Form is subject to the terms of the Mozilla Public
10
 * License, v. 2.0. If a copy of the MPL was not distributed with this
11
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12
 */
13
14
namespace SteamScore\Api\Factory;
15
16
use Doctrine\DBAL\Types\Type;
17
use Doctrine\ORM\EntityManager;
18
use Doctrine\ORM\EntityManagerInterface;
19
use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver;
20
use Doctrine\ORM\Tools\Setup;
21
use Interop\Container\ContainerInterface;
22
use Ramsey\Uuid\Doctrine\UuidBinaryType;
23
24
final class EntityManagerFactory
25
{
26
    /**
27
     * Creates an instanced implementation of `Doctrine\ORM\EntityManagerInterface`.
28
     *
29
     * @param ContainerInterface $container
30
     *
31
     * @return EntityManagerInterface
32
     */
33
    public function __invoke(ContainerInterface $container): EntityManagerInterface
34
    {
35
        if (Type::hasType('uuid_binary') === false) {
36
            Type::addType('uuid_binary', UuidBinaryType::class);
37
        }
38
39
        $appConfig = $container->get('config');
40
        $ormConfig = Setup::createConfiguration($appConfig['debug'], $appConfig['orm']['proxies']);
41
        $driver = new SimplifiedXmlDriver($appConfig['orm']['mapping']);
42
43
        $ormConfig->setMetadataDriverImpl($driver);
44
45
        return EntityManager::create($appConfig['orm']['connection'], $ormConfig);
46
    }
47
}
48