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

GravitonDocumentExtension::getConfigDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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