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