Completed
Push — feature/EVO-7278-security-and-... ( e30f5a...fbbb1a )
by
unknown
09:38
created

GravitonDocumentBundle   B

Complexity

Total Complexity 5

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 16

Test Coverage

Coverage 94.23%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 16
dl 0
loc 93
ccs 49
cts 52
cp 0.9423
rs 8.4614
c 1
b 0
f 0

4 Methods

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