Completed
Push — master ( f1dd04...77e978 )
by Beñat
01:46
created

RoutesPass::process()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 20
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the BenGorFile package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorFile\FileBundle\DependencyInjection\Compiler;
14
15
use BenGorFile\FileBundle\DependencyInjection\Compiler\Routing\DownloadRoutesLoaderBuilder;
16
use BenGorFile\FileBundle\DependencyInjection\Compiler\Routing\GetFilesRoutesLoaderBuilder;
17
use BenGorFile\FileBundle\DependencyInjection\Compiler\Routing\UploadRoutesLoaderBuilder;
18
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19
use Symfony\Component\DependencyInjection\ContainerBuilder;
20
21
/**
22
 * Load routes compiler pass.
23
 *
24
 * Based on configuration the routes are created dynamically.
25
 *
26
 * @author Beñat Espiña <[email protected]>
27
 */
28
class RoutesPass implements CompilerPassInterface
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function process(ContainerBuilder $container)
34
    {
35
        $config = $container->getParameter('bengor_file.config');
36
37
        $downloadConfiguration = [];
38
        $getFilesConfiguration = [];
39
        $uploadConfiguration = [];
40
41
        foreach ($config['file_class'] as $key => $file) {
42
            $downloadConfiguration[$key] = [
43
                'storage'            => $file['storage'],
44
                'upload_destination' => $file['upload_destination'],
45
                'download_base_url'  => $file['download_base_url'],
46
            ];
47
            $getFilesConfiguration[$key] = array_merge(
48
                $file['use_cases']['get_files'],
49
                $file['routes']['get_files']
50
            );
51
            $uploadConfiguration[$key] = array_merge(
52
                $file['use_cases']['upload'],
53
                $file['routes']['upload']
54
            );
55
            $uploadConfiguration[$key]['upload_strategy'] = $file['upload_strategy'];
56
        }
57
58
        (new DownloadRoutesLoaderBuilder($container, $downloadConfiguration))->build();
59
        (new GetFilesRoutesLoaderBuilder($container, $getFilesConfiguration))->build();
60
        (new UploadRoutesLoaderBuilder($container, $uploadConfiguration))->build();
61
    }
62
}
63