|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* integrate the mongodb flavour of the doctrine2-odm with graviton |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\DocumentBundle; |
|
7
|
|
|
|
|
8
|
|
|
use Graviton\DocumentBundle\DependencyInjection\Compiler\DocumentMapCompilerPass; |
|
9
|
|
|
use Graviton\DocumentBundle\DependencyInjection\Compiler\ReadOnlyFieldsCompilerPass; |
|
10
|
|
|
use Graviton\DocumentBundle\DependencyInjection\Compiler\RecordOriginExceptionFieldsCompilerPass; |
|
11
|
|
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig; |
|
12
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle; |
|
13
|
|
|
use Graviton\BundleBundle\GravitonBundleInterface; |
|
14
|
|
|
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle; |
|
15
|
|
|
use Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle; |
|
16
|
|
|
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle; |
|
17
|
|
|
use Doctrine\ODM\MongoDB\Types\Type; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
19
|
|
|
use Graviton\DocumentBundle\DependencyInjection\Compiler\ExtRefMappingCompilerPass; |
|
20
|
|
|
use Graviton\DocumentBundle\DependencyInjection\Compiler\ExtRefFieldsCompilerPass; |
|
21
|
|
|
use Graviton\DocumentBundle\DependencyInjection\Compiler\RqlFieldsCompilerPass; |
|
22
|
|
|
use Graviton\DocumentBundle\DependencyInjection\Compiler\TranslatableFieldsCompilerPass; |
|
23
|
|
|
use Graviton\DocumentBundle\DependencyInjection\Compiler\DocumentFieldNamesCompilerPass; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* GravitonDocumentBundle |
|
27
|
|
|
* |
|
28
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
29
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
30
|
|
|
* @link http://swisscom.ch |
|
31
|
|
|
*/ |
|
32
|
|
|
class GravitonDocumentBundle extends Bundle implements GravitonBundleInterface |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* initialize bundle |
|
36
|
|
|
*/ |
|
37
|
18 |
|
public function __construct() |
|
38
|
|
|
{ |
|
39
|
|
|
// TODO: implement ExtReferenceArrayType |
|
40
|
18 |
|
Type::registerType('extref', Types\ExtReferenceType::class); |
|
41
|
18 |
|
Type::registerType('hash', Types\HashType::class); |
|
42
|
18 |
|
Type::registerType('hasharray', Types\HashArrayType::class); |
|
43
|
18 |
|
Type::registerType('datearray', Types\DateArrayType::class); |
|
44
|
18 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritDoc} |
|
49
|
|
|
* |
|
50
|
|
|
* @return \Symfony\Component\HttpKernel\Bundle\Bundle[] |
|
|
|
|
|
|
51
|
|
|
*/ |
|
52
|
18 |
|
public function getBundles() |
|
53
|
|
|
{ |
|
54
|
|
|
return array( |
|
55
|
18 |
|
new DoctrineMongoDBBundle(), |
|
56
|
18 |
|
new StofDoctrineExtensionsBundle(), |
|
57
|
18 |
|
new DoctrineFixturesBundle(), |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* load compiler pass |
|
63
|
|
|
* |
|
64
|
|
|
* @param ContainerBuilder $container container builder |
|
65
|
|
|
* |
|
66
|
|
|
* @return void |
|
67
|
|
|
*/ |
|
68
|
2 |
|
public function build(ContainerBuilder $container) |
|
69
|
|
|
{ |
|
70
|
2 |
|
parent::build($container); |
|
71
|
|
|
|
|
72
|
2 |
|
$container->addCompilerPass( |
|
73
|
2 |
|
new DocumentMapCompilerPass(), |
|
74
|
2 |
|
PassConfig::TYPE_BEFORE_OPTIMIZATION, |
|
75
|
2 |
|
100 |
|
76
|
|
|
); |
|
77
|
2 |
|
$container->addCompilerPass( |
|
78
|
2 |
|
new ExtRefMappingCompilerPass(), |
|
79
|
2 |
|
PassConfig::TYPE_BEFORE_OPTIMIZATION, |
|
80
|
2 |
|
5 |
|
81
|
|
|
); |
|
82
|
2 |
|
$container->addCompilerPass( |
|
83
|
2 |
|
new ExtRefFieldsCompilerPass(), |
|
84
|
2 |
|
PassConfig::TYPE_BEFORE_OPTIMIZATION, |
|
85
|
2 |
|
5 |
|
86
|
|
|
); |
|
87
|
2 |
|
$container->addCompilerPass( |
|
88
|
2 |
|
new RqlFieldsCompilerPass(), |
|
89
|
2 |
|
PassConfig::TYPE_BEFORE_OPTIMIZATION, |
|
90
|
2 |
|
5 |
|
91
|
|
|
); |
|
92
|
2 |
|
$container->addCompilerPass( |
|
93
|
2 |
|
new TranslatableFieldsCompilerPass(), |
|
94
|
2 |
|
PassConfig::TYPE_BEFORE_OPTIMIZATION, |
|
95
|
2 |
|
5 |
|
96
|
|
|
); |
|
97
|
2 |
|
$container->addCompilerPass( |
|
98
|
2 |
|
new DocumentFieldNamesCompilerPass(), |
|
99
|
2 |
|
PassConfig::TYPE_BEFORE_OPTIMIZATION, |
|
100
|
2 |
|
5 |
|
101
|
|
|
); |
|
102
|
2 |
|
$container->addCompilerPass( |
|
103
|
2 |
|
new ReadOnlyFieldsCompilerPass(), |
|
104
|
2 |
|
PassConfig::TYPE_BEFORE_OPTIMIZATION, |
|
105
|
2 |
|
5 |
|
106
|
|
|
); |
|
107
|
2 |
|
$container->addCompilerPass( |
|
108
|
2 |
|
new RecordOriginExceptionFieldsCompilerPass(), |
|
109
|
2 |
|
PassConfig::TYPE_BEFORE_OPTIMIZATION, |
|
110
|
2 |
|
5 |
|
111
|
|
|
); |
|
112
|
2 |
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* boot bundle function |
|
116
|
|
|
* |
|
117
|
|
|
* @return void |
|
118
|
|
|
*/ |
|
119
|
18 |
|
public function boot() |
|
120
|
|
|
{ |
|
121
|
18 |
|
$extRefConverter = $this->container->get('graviton.document.service.extrefconverter'); |
|
122
|
18 |
|
$customType = Type::getType('hash'); |
|
123
|
18 |
|
$customType->setExtRefConverter($extRefConverter); |
|
124
|
18 |
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.