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\ReadOnlyFieldsCompilerPass; |
9
|
|
|
use Graviton\DocumentBundle\DependencyInjection\Compiler\RecordOriginExceptionFieldsCompilerPass; |
10
|
|
|
use Graviton\DocumentBundle\DependencyInjection\Compiler\Utils\DocumentMap; |
11
|
|
|
use Symfony\Component\Finder\Finder; |
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
|
4 |
|
public function __construct() |
38
|
|
|
{ |
39
|
|
|
// TODO: implement ExtReferenceArrayType |
40
|
4 |
|
Type::registerType('extref', Types\ExtReferenceType::class); |
41
|
4 |
|
Type::registerType('hash', Types\HashType::class); |
42
|
4 |
|
Type::registerType('hasharray', Types\HashArrayType::class); |
43
|
4 |
|
Type::registerType('datearray', Types\DateArrayType::class); |
44
|
4 |
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
* |
50
|
|
|
* @return \Symfony\Component\HttpKernel\Bundle\Bundle[] |
|
|
|
|
51
|
|
|
*/ |
52
|
4 |
|
public function getBundles() |
53
|
|
|
{ |
54
|
|
|
return array( |
55
|
4 |
|
new DoctrineMongoDBBundle(), |
56
|
4 |
|
new StofDoctrineExtensionsBundle(), |
57
|
4 |
|
new DoctrineFixturesBundle(), |
58
|
2 |
|
); |
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
|
|
|
// If it's inside vendor library or running as graviton base. |
73
|
2 |
|
$rootDir = $container->getParameter('kernel.root_dir'); |
74
|
2 |
|
if (strpos($rootDir, 'vendor/graviton')) { |
75
|
|
|
$dirs = [ |
76
|
|
|
$rootDir.'/../..' |
77
|
|
|
]; |
78
|
|
|
} else { |
79
|
|
|
$dirs = [ |
80
|
2 |
|
__DIR__ . '/../..', |
81
|
1 |
|
$rootDir.'/../vendor/graviton' |
82
|
1 |
|
]; |
83
|
|
|
} |
84
|
|
|
|
85
|
2 |
|
$documentMap = new DocumentMap( |
86
|
2 |
|
(new Finder()) |
87
|
2 |
|
->in($dirs) |
88
|
2 |
|
->path('Resources/config/doctrine') |
89
|
2 |
|
->name('*.mongodb.xml'), |
90
|
2 |
|
(new Finder()) |
91
|
2 |
|
->in($dirs) |
92
|
2 |
|
->path('Resources/config/serializer') |
93
|
2 |
|
->name('*.xml'), |
94
|
2 |
|
(new Finder()) |
95
|
2 |
|
->in($dirs) |
96
|
2 |
|
->path('Resources/config') |
97
|
2 |
|
->name('validation.xml'), |
98
|
2 |
|
(new Finder()) |
99
|
2 |
|
->in($dirs) |
100
|
2 |
|
->path('Resources/config/schema') |
101
|
2 |
|
->name('*.json') |
102
|
1 |
|
); |
103
|
|
|
|
104
|
2 |
|
$container->addCompilerPass(new ExtRefMappingCompilerPass()); |
105
|
2 |
|
$container->addCompilerPass(new ExtRefFieldsCompilerPass($documentMap)); |
106
|
2 |
|
$container->addCompilerPass(new RqlFieldsCompilerPass($documentMap)); |
107
|
2 |
|
$container->addCompilerPass(new TranslatableFieldsCompilerPass($documentMap)); |
108
|
2 |
|
$container->addCompilerPass(new DocumentFieldNamesCompilerPass($documentMap)); |
109
|
2 |
|
$container->addCompilerPass(new ReadOnlyFieldsCompilerPass($documentMap)); |
110
|
2 |
|
$container->addCompilerPass(new RecordOriginExceptionFieldsCompilerPass($documentMap)); |
111
|
2 |
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* boot bundle function |
115
|
|
|
* |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
4 |
|
public function boot() |
119
|
|
|
{ |
120
|
4 |
|
$extRefConverter = $this->container->get('graviton.document.service.extrefconverter'); |
121
|
4 |
|
$customType = Type::getType('hash'); |
122
|
4 |
|
$customType->setExtRefConverter($extRefConverter); |
123
|
4 |
|
} |
124
|
|
|
} |
125
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.