Completed
Push — feature/some-cleanups ( c7b655 )
by Narcotic
14:56
created

GravitonDocumentBundle::getBundles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
crap 1
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 Doctrine\ODM\MongoDB\Types\Type;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Graviton\DocumentBundle\DependencyInjection\Compiler\ExtRefMappingCompilerPass;
16
use Graviton\DocumentBundle\DependencyInjection\Compiler\ExtRefFieldsCompilerPass;
17
use Graviton\DocumentBundle\DependencyInjection\Compiler\RqlFieldsCompilerPass;
18
use Graviton\DocumentBundle\DependencyInjection\Compiler\TranslatableFieldsCompilerPass;
19
use Graviton\DocumentBundle\DependencyInjection\Compiler\DocumentFieldNamesCompilerPass;
20
21
/**
22
 * GravitonDocumentBundle
23
 *
24
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
25
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
26
 * @link     http://swisscom.ch
27
 */
28
class GravitonDocumentBundle extends Bundle
29
{
30
    /**
31
     * initialize bundle
32
     */
33 18
    public function __construct()
34
    {
35
        // TODO: implement ExtReferenceArrayType
36 18
        Type::registerType('extref', Types\ExtReferenceType::class);
37 18
        Type::registerType('hash', Types\HashType::class);
38 18
        Type::registerType('hasharray', Types\HashArrayType::class);
39 18
        Type::registerType('datearray', Types\DateArrayType::class);
40 18
    }
41
42
    /**
43
     * load compiler pass
44
     *
45
     * @param ContainerBuilder $container container builder
46
     *
47
     * @return void
48
     */
49 2
    public function build(ContainerBuilder $container)
50
    {
51 2
        parent::build($container);
52
53 2
        $container->addCompilerPass(
54 2
            new DocumentMapCompilerPass(),
55 2
            PassConfig::TYPE_BEFORE_OPTIMIZATION,
56 2
            100
57
        );
58 2
        $container->addCompilerPass(
59 2
            new ExtRefMappingCompilerPass(),
60 2
            PassConfig::TYPE_BEFORE_OPTIMIZATION,
61 2
            5
62
        );
63 2
        $container->addCompilerPass(
64 2
            new ExtRefFieldsCompilerPass(),
65 2
            PassConfig::TYPE_BEFORE_OPTIMIZATION,
66 2
            5
67
        );
68 2
        $container->addCompilerPass(
69 2
            new RqlFieldsCompilerPass(),
70 2
            PassConfig::TYPE_BEFORE_OPTIMIZATION,
71 2
            5
72
        );
73 2
        $container->addCompilerPass(
74 2
            new TranslatableFieldsCompilerPass(),
75 2
            PassConfig::TYPE_BEFORE_OPTIMIZATION,
76 2
            5
77
        );
78 2
        $container->addCompilerPass(
79 2
            new DocumentFieldNamesCompilerPass(),
80 2
            PassConfig::TYPE_BEFORE_OPTIMIZATION,
81 2
            5
82
        );
83 2
        $container->addCompilerPass(
84 2
            new ReadOnlyFieldsCompilerPass(),
85 2
            PassConfig::TYPE_BEFORE_OPTIMIZATION,
86 2
            5
87
        );
88 2
        $container->addCompilerPass(
89 2
            new RecordOriginExceptionFieldsCompilerPass(),
90 2
            PassConfig::TYPE_BEFORE_OPTIMIZATION,
91 2
            5
92
        );
93 2
    }
94
95
    /**
96
     * boot bundle function
97
     *
98
     * @return void
99
     */
100 18
    public function boot()
101
    {
102 18
        $extRefConverter = $this->container->get('graviton.document.service.extrefconverter');
103 18
        $customType = Type::getType('hash');
104 18
        $customType->setExtRefConverter($extRefConverter);
105 18
    }
106
}
107