Completed
Push — feature/EVO-8294-file-upload-r... ( ebbdfa )
by
unknown
63:34
created

GravitonArchiveExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigDir() 0 4 1
B prepend() 0 31 3
1
<?php
2
3
namespace Graviton\ArchiveBundle\DependencyInjection;
4
5
use Graviton\BundleBundle\DependencyInjection\GravitonBundleExtension;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
/**
9
 * This is the class that loads and manages your bundle configuration.
10
 *
11
 * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
12
 */
13
class GravitonArchiveExtension extends GravitonBundleExtension
14
{
15
    /**
16
     * get path to bundles Resources/config dir
17
     *
18
     * @return string
19
     */
20
    public function getConfigDir()
21
    {
22
        return __DIR__.'/../Resources/config';
23
    }
24
25
    /**
26
     * Overwrite S3 config from cloud if available
27
     *
28
     * @param ContainerBuilder $container instance
29
     *
30
     * @return void
31
     */
32
    public function prepend(ContainerBuilder $container)
33
    {
34
        parent::prepend($container);
35
36
        // populated from cf's VCAP_SERVICES variable
37
        $services = getenv('VCAP_SERVICES');
38
        if (!empty($services)) {
39
            $services = json_decode($services, true);
40
            $creds = $services['dynstrg'][0]['credentials'];
41
            $sets = [
42
                'graviton.file.gaufrette.backend'   => 's3',
43
                'graviton.aws_s3.client.endpoint'   => sprintf('https://%s', $creds['accessHost']),
44
                'graviton.aws_s3.client.key'        => $creds['accessKey'],
45
                'graviton.aws_s3.client.secret'     => $creds['sharedSecret'],
46
                'graviton.aws_s3.bucket_name'       => $services['dynstrg'][0]['name']
47
            ];
48
        } else {
49
            $sets = [
50
                'graviton.file.gaufrette.backend'   => $container->getParameter('graviton.file.backend'),
51
                'graviton.aws_s3.client.endpoint'   => $container->getParameter('graviton.file.s3.endpoint'),
52
                'graviton.aws_s3.client.key'        => $container->getParameter('graviton.file.s3.key'),
53
                'graviton.aws_s3.client.secret'     => $container->getParameter('graviton.file.s3.key'),
54
                'graviton.aws_s3.bucket_name'       => $container->getParameter('graviton.file.s3.bucket_name')
55
            ];
56
        }
57
58
        // Set Values
59
        foreach ($sets as $set => $value) {
60
            $container->setParameter($set,  $value);
0 ignored issues
show
Coding Style introduced by
Expected 1 space instead of 2 after comma in function call.
Loading history...
61
        }
62
    }
63
}
64