1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the BenGorUser package. |
5
|
|
|
* |
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace BenGorUser\DoctrineORMBridge\Infrastructure\Persistence; |
14
|
|
|
|
15
|
|
|
use BenGorUser\DoctrineORMBridge\Infrastructure\Persistence\Types\UserIdType; |
16
|
|
|
use BenGorUser\DoctrineORMBridge\Infrastructure\Persistence\Types\UserRolesType; |
17
|
|
|
use Doctrine\DBAL\Types\Type; |
18
|
|
|
use Doctrine\ORM\EntityManager; |
19
|
|
|
use Doctrine\ORM\Tools\Setup; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Doctrine ORM entity manager factory class. |
23
|
|
|
* |
24
|
|
|
* @author Beñat Espiña <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class EntityManagerFactory |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Creates an entity manager instance enabling mappings and custom types. |
30
|
|
|
* |
31
|
|
|
* @param mixed $aConnection Connection parameters as db driver |
32
|
|
|
* @param array $mappingsPaths The mapping files diretory paths |
33
|
|
|
* @param bool $isDevMode Enables the dev mode, by default is enabled |
34
|
|
|
* |
35
|
|
|
* @return EntityManager |
36
|
|
|
*/ |
37
|
|
|
public function build($aConnection, array $mappingsPaths = [], $isDevMode = true) |
38
|
|
|
{ |
39
|
|
|
if (empty($mappingsPaths)) { |
40
|
|
|
$mappingsPaths = [__DIR__ . '/Mapping']; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
Type::addType('user_id', UserIdType::class); |
44
|
|
|
Type::addType('user_roles', UserRolesType::class); |
45
|
|
|
|
46
|
|
|
return EntityManager::create( |
47
|
|
|
$aConnection, |
48
|
|
|
Setup::createYAMLMetadataConfiguration($mappingsPaths, $isDevMode) |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|