Completed
Push — feature/EVO-6307-record-origin... ( 2c1fcb...797eb1 )
by Narcotic
97:17 queued 32:45
created

GravitonDocumentBundle::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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
    public function __construct()
38
    {
39
        // TODO: implement ExtReferenceArrayType
40
        Type::registerType('extref', Types\ExtReferenceType::class);
41
        Type::registerType('hash', Types\HashType::class);
42
        Type::registerType('hasharray', Types\HashArrayType::class);
43
        Type::registerType('datearray', Types\DateArrayType::class);
44
    }
45
46
47
    /**
48
     * {@inheritDoc}
49
     *
50
     * @return \Symfony\Component\HttpKernel\Bundle\Bundle[]
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<DoctrineMongoDBBun...DoctrineFixturesBundle>.

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.

Loading history...
51
     */
52
    public function getBundles()
53
    {
54
        return array(
55
            new DoctrineMongoDBBundle(),
56
            new StofDoctrineExtensionsBundle(),
57
            new DoctrineFixturesBundle(),
58
        );
59
    }
60
61
    /**
62
     * load compiler pass
63
     *
64
     * @param ContainerBuilder $container container builder
65
     *
66
     * @return void
67
     */
68
    public function build(ContainerBuilder $container)
69
    {
70
        parent::build($container);
71
72
        $documentMap = new DocumentMap(
73
            (new Finder())
74
                ->in(__DIR__ . '/../..')
75
                ->path('Resources/config/doctrine')
76
                ->name('*.mongodb.xml'),
77
            (new Finder())
78
                ->in(__DIR__ . '/../..')
79
                ->path('Resources/config/serializer')
80
                ->name('*.xml'),
81
            (new Finder())
82
                ->in(__DIR__ . '/../..')
83
                ->path('Resources/config')
84
                ->name('validation.xml'),
85
            (new Finder())
86
                ->in(__DIR__ . '/../..')
87
                ->path('Resources/config/schema')
88
                ->name('*.json')
89
        );
90
91
        $container->addCompilerPass(new ExtRefMappingCompilerPass());
92
        $container->addCompilerPass(new ExtRefFieldsCompilerPass($documentMap));
93
        $container->addCompilerPass(new RqlFieldsCompilerPass($documentMap));
94
        $container->addCompilerPass(new TranslatableFieldsCompilerPass($documentMap));
95
        $container->addCompilerPass(new DocumentFieldNamesCompilerPass($documentMap));
96
        $container->addCompilerPass(new ReadOnlyFieldsCompilerPass($documentMap));
97
        $container->addCompilerPass(new RecordOriginExceptionFieldsCompilerPass($documentMap));
98
    }
99
100
    /**
101
     * boot bundle function
102
     *
103
     * @return void
104
     */
105
    public function boot()
106
    {
107
        $extRefConverter = $this->container->get('graviton.document.service.extrefconverter');
108
        $customType = Type::getType('hash');
109
        $customType->setExtRefConverter($extRefConverter);
110
    }
111
}
112