Completed
Push — feature/EVO-5751-mongodb-3.x ( e24a58...f7410f )
by Lucas
65:41
created

GravitonDocumentBundle   B

Complexity

Total Complexity 4

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 16

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 4
lcom 0
cbo 16
dl 0
loc 80
ccs 43
cts 43
cp 1
rs 8.4614
c 3
b 0
f 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getBundles() 0 8 1
B build() 0 31 1
A boot() 0 6 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\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 8
     */
37
    public function __construct()
38
    {
39 8
        // TODO: implement ExtReferenceArrayType
40 8
        Type::registerType('extref', Types\ExtReferenceType::class);
41 8
        Type::registerType('hash', Types\HashType::class);
42 8
        Type::registerType('hasharray', Types\HashArrayType::class);
43 8
        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 8
     */
52
    public function getBundles()
53
    {
54 8
        return array(
55 8
            new DoctrineMongoDBBundle(),
56 8
            new StofDoctrineExtensionsBundle(),
57 4
            new DoctrineFixturesBundle(),
58
        );
59
    }
60
61
    /**
62
     * load compiler pass
63
     *
64
     * @param ContainerBuilder $container container builder
65
     *
66
     * @return void
67 2
     */
68
    public function build(ContainerBuilder $container)
69 2
    {
70
        parent::build($container);
71 2
72 2
        $documentMap = new DocumentMap(
73 2
            (new Finder())
74 2
                ->in(__DIR__ . '/../..')
75 2
                ->path('Resources/config/doctrine')
76 2
                ->name('*.mongodb.xml'),
77 2
            (new Finder())
78 2
                ->in(__DIR__ . '/../..')
79 2
                ->path('Resources/config/serializer')
80 2
                ->name('*.xml'),
81 2
            (new Finder())
82 2
                ->in(__DIR__ . '/../..')
83 2
                ->path('Resources/config')
84 2
                ->name('validation.xml'),
85 2
            (new Finder())
86 2
                ->in(__DIR__ . '/../..')
87 2
                ->path('Resources/config/schema')
88 1
                ->name('*.json')
89
        );
90 2
91 2
        $container->addCompilerPass(new ExtRefMappingCompilerPass());
92 2
        $container->addCompilerPass(new ExtRefFieldsCompilerPass($documentMap));
93 2
        $container->addCompilerPass(new RqlFieldsCompilerPass($documentMap));
94 2
        $container->addCompilerPass(new TranslatableFieldsCompilerPass($documentMap));
95 2
        $container->addCompilerPass(new DocumentFieldNamesCompilerPass($documentMap));
96 2
        $container->addCompilerPass(new ReadOnlyFieldsCompilerPass($documentMap));
97
        $container->addCompilerPass(new RecordOriginExceptionFieldsCompilerPass($documentMap));
98
    }
99
100
    /**
101
     * boot bundle function
102
     *
103 8
     * @return void
104
     */
105 8
    public function boot()
106 8
    {
107 8
        $extRefConverter = $this->container->get('graviton.document.service.extrefconverter');
108 8
        $customType = Type::getType('hash');
109
        $customType->setExtRefConverter($extRefConverter);
110
    }
111
}
112