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

GravitonArchiveExtension::prepend()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 31
rs 8.8571
cc 3
eloc 21
nc 4
nop 1
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