Completed
Push — feature/some-cleanups ( c7b655...943465 )
by Narcotic
16:33
created

GravitonDocumentBundle::getBundles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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