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\DoctrineODMMongoDBBridge\Infrastructure\Persistence; |
14
|
|
|
|
15
|
|
|
use BenGorUser\DoctrineODMMongoDBBridge\Infrastructure\Persistence\Types\UserEmailType; |
16
|
|
|
use BenGorUser\DoctrineODMMongoDBBridge\Infrastructure\Persistence\Types\UserIdType; |
17
|
|
|
use BenGorUser\DoctrineODMMongoDBBridge\Infrastructure\Persistence\Types\UserPasswordType; |
18
|
|
|
use BenGorUser\DoctrineODMMongoDBBridge\Infrastructure\Persistence\Types\UserRolesType; |
19
|
|
|
use BenGorUser\DoctrineODMMongoDBBridge\Infrastructure\Persistence\Types\UserTokenType; |
20
|
|
|
use Doctrine\MongoDB\Connection; |
21
|
|
|
use Doctrine\ODM\MongoDB\Configuration; |
22
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
23
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver; |
24
|
|
|
use Doctrine\ODM\MongoDB\Types\Type; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Doctrine ODM MongoDB document manager factory class. |
28
|
|
|
* |
29
|
|
|
* @author Beñat Espiña <[email protected]> |
30
|
|
|
*/ |
31
|
|
|
class DocumentManagerFactory |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Creates an document manager instance enabling mappings and custom types. |
35
|
|
|
* |
36
|
|
|
* @param Connection|null $aConnection The MongoDB connection, it can be null |
37
|
|
|
* |
38
|
|
|
* @return DocumentManager |
39
|
|
|
*/ |
40
|
|
|
public function build(Connection $aConnection = null) |
41
|
|
|
{ |
42
|
|
|
Type::addType('user_email', UserEmailType::class); |
43
|
|
|
Type::addType('user_id', UserIdType::class); |
44
|
|
|
Type::addType('user_password', UserPasswordType::class); |
45
|
|
|
Type::addType('user_roles', UserRolesType::class); |
46
|
|
|
Type::addType('user_token', UserTokenType::class); |
47
|
|
|
|
48
|
|
|
$configuration = new Configuration(); |
49
|
|
|
$driver = new YamlDriver([__DIR__ . '/Mapping']); |
50
|
|
|
$configuration->setMetadataDriverImpl($driver); |
51
|
|
|
$configuration->setProxyDir(__DIR__ . '/Proxies'); |
52
|
|
|
$configuration->setProxyNamespace('Proxies'); |
53
|
|
|
$configuration->setHydratorDir(__DIR__ . '/Hydrators'); |
54
|
|
|
$configuration->setHydratorNamespace('Hydrators'); |
55
|
|
|
|
56
|
|
|
return DocumentManager::create($aConnection, $configuration); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|