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

GravitonDocumentExtension::prepend()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0438

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 23
ccs 7
cts 9
cp 0.7778
rs 9.0856
cc 2
eloc 15
nc 2
nop 1
crap 2.0438
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