Completed
Push — master ( 2329f6...21d34e )
by Lucas
13:38 queued 03:35
created

GravitonDocumentExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 75%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 45
ccs 9
cts 12
cp 0.75
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigDir() 0 4 1
A prepend() 0 23 2
1
<?php
2
/**
3
 * manage and load bundle config.
4
 */
5
6
namespace Graviton\DocumentBundle\DependencyInjection;
7
8
use Graviton\BundleBundle\DependencyInjection\GravitonBundleExtension;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
11
/**
12
 * This is the class that loads and manages your bundle configuration
13
 *
14
 * To learn more see {@link http://scm.to/004w}
15
 *
16
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
17
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
18
 * @link     http://swisscom.ch
19
 */
20
class GravitonDocumentExtension extends GravitonBundleExtension
21
{
22
    /**
23
     * {@inheritDoc}
24
     *
25
     * @return string
26
     */
27 1
    public function getConfigDir()
28
    {
29 1
        return __DIR__ . '/../Resources/config';
30
    }
31
32
    /**
33
     * {@inheritDoc}
34
     *
35
     * Overwrite mongodb config from parent in cloud case.
36
     *
37
     * @param ContainerBuilder $container instance
38
     *
39
     * @return void
40
     */
41 1
    public function prepend(ContainerBuilder $container)
42
    {
43 1
        parent::prepend($container);
44
45
        // grab mongo config directly from vcap...
46
        $services = getenv('VCAP_SERVICES');
47
        if (!empty($services)) {
48
            $services = json_decode($services, true);
49
            $mongo = $services['mongodb'][0]['credentials'];
50
51
            $container->setParameter('mongodb.default.server.uri', $mongo['uri']);
52
            $container->setParameter('mongodb.default.server.db', $mongo['database']);
53
        } else {
54
            $container->setParameter(
55 1
                'mongodb.default.server.uri',
56 1
                $container->getParameter('graviton.mongodb.default.server.uri')
57
            );
58
            $container->setParameter(
59 1
                'mongodb.default.server.db',
60
                $container->getParameter('graviton.mongodb.default.server.db')
61
            );
62 1
        }
63 1
    }
64
}
65