Completed
Push — feature/EVO-5751-text-index-mo... ( 0ab3ac...8fecb1 )
by
unknown
62:16 queued 57:01
created

GravitonDocumentBundle   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 15

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
lcom 0
cbo 15
dl 0
loc 79
rs 9.1666
c 2
b 0
f 1
ccs 43
cts 43
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getBundles() 0 8 1
B build() 0 30 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\Utils\DocumentMap;
10
use Symfony\Component\Finder\Finder;
11
use Symfony\Component\HttpKernel\Bundle\Bundle;
12
use Graviton\BundleBundle\GravitonBundleInterface;
13
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
14
use Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle;
15
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
16
use Doctrine\ODM\MongoDB\Types\Type;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Graviton\DocumentBundle\DependencyInjection\Compiler\ExtRefMappingCompilerPass;
19
use Graviton\DocumentBundle\DependencyInjection\Compiler\ExtRefFieldsCompilerPass;
20
use Graviton\DocumentBundle\DependencyInjection\Compiler\RqlFieldsCompilerPass;
21
use Graviton\DocumentBundle\DependencyInjection\Compiler\TranslatableFieldsCompilerPass;
22
use Graviton\DocumentBundle\DependencyInjection\Compiler\DocumentFieldNamesCompilerPass;
23
24
/**
25
 * GravitonDocumentBundle
26
 *
27
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
28
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
29
 * @link     http://swisscom.ch
30
 */
31
class GravitonDocumentBundle extends Bundle implements GravitonBundleInterface
32
{
33
    /**
34
     * initialize bundle
35
     */
36 6
    public function __construct()
37
    {
38
        // TODO: implement ExtReferenceArrayType
39 6
        Type::registerType('extref', Types\ExtReferenceType::class);
40 6
        Type::registerType('hash', Types\HashType::class);
41 6
        Type::registerType('hasharray', Types\HashArrayType::class);
42 6
        Type::registerType('datearray', Types\DateArrayType::class);
43 6
    }
44
45
46
    /**
47
     * {@inheritDoc}
48
     *
49
     * @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...
50
     */
51 6
    public function getBundles()
52
    {
53
        return array(
54 6
            new DoctrineMongoDBBundle(),
55 6
            new StofDoctrineExtensionsBundle(),
56 6
            new DoctrineFixturesBundle(),
57 3
        );
58
    }
59
60
    /**
61
     * load compiler pass
62
     *
63
     * @param ContainerBuilder $container container builder
64
     *
65
     * @return void
66
     */
67 2
    public function build(ContainerBuilder $container)
68
    {
69 2
        parent::build($container);
70
71 2
        $documentMap = new DocumentMap(
72 2
            (new Finder())
73 2
                ->in(__DIR__ . '/../..')
74 2
                ->path('Resources/config/doctrine')
75 2
                ->name('*.mongodb.xml'),
76 2
            (new Finder())
77 2
                ->in(__DIR__ . '/../..')
78 2
                ->path('Resources/config/serializer')
79 2
                ->name('*.xml'),
80 2
            (new Finder())
81 2
                ->in(__DIR__ . '/../..')
82 2
                ->path('Resources/config')
83 2
                ->name('validation.xml'),
84 2
            (new Finder())
85 2
                ->in(__DIR__ . '/../..')
86 2
                ->path('Resources/config/schema')
87 2
                ->name('*.json')
88 1
        );
89
90 2
        $container->addCompilerPass(new ExtRefMappingCompilerPass());
91 2
        $container->addCompilerPass(new ExtRefFieldsCompilerPass($documentMap));
92 2
        $container->addCompilerPass(new RqlFieldsCompilerPass($documentMap));
93 2
        $container->addCompilerPass(new TranslatableFieldsCompilerPass($documentMap));
94 2
        $container->addCompilerPass(new DocumentFieldNamesCompilerPass($documentMap));
95 2
        $container->addCompilerPass(new ReadOnlyFieldsCompilerPass($documentMap));
96 2
    }
97
98
    /**
99
     * boot bundle function
100
     *
101
     * @return void
102
     */
103 6
    public function boot()
104
    {
105 6
        $extRefConverter = $this->container->get('graviton.document.service.extrefconverter');
106 6
        $customType = Type::getType('hash');
107 6
        $customType->setExtRefConverter($extRefConverter);
108 6
    }
109
}
110