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\GetFileRoutesLoaderBuilder; |
17
|
|
|
use BenGorFile\FileBundle\DependencyInjection\Compiler\Routing\GetFilesRoutesLoaderBuilder; |
18
|
|
|
use BenGorFile\FileBundle\DependencyInjection\Compiler\Routing\UploadRoutesLoaderBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Load routes compiler pass. |
24
|
|
|
* |
25
|
|
|
* Based on configuration the routes are created dynamically. |
26
|
|
|
* |
27
|
|
|
* @author Beñat Espiña <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
class RoutesPass implements CompilerPassInterface |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function process(ContainerBuilder $container) |
35
|
|
|
{ |
36
|
|
|
$config = $container->getParameter('bengor_file.config'); |
37
|
|
|
|
38
|
|
|
$downloadConfiguration = []; |
39
|
|
|
$getFilesConfiguration = []; |
40
|
|
|
$getFileConfiguration = []; |
41
|
|
|
$uploadConfiguration = []; |
42
|
|
|
|
43
|
|
|
foreach ($config['file_class'] as $key => $file) { |
44
|
|
|
$downloadConfiguration[$key] = [ |
45
|
|
|
'storage' => $file['storage'], |
46
|
|
|
'upload_destination' => $file['upload_destination'], |
47
|
|
|
'download_base_url' => $file['download_base_url'], |
48
|
|
|
]; |
49
|
|
|
$getFilesConfiguration[$key] = array_merge( |
50
|
|
|
$file['use_cases']['get_files'], |
51
|
|
|
$file['routes']['get_files'] |
52
|
|
|
); |
53
|
|
|
$getFileConfiguration[$key] = array_merge( |
54
|
|
|
$file['use_cases']['get_file'], |
55
|
|
|
$file['routes']['get_file'] |
56
|
|
|
); |
57
|
|
|
$uploadConfiguration[$key] = array_merge( |
58
|
|
|
$file['use_cases']['upload'], |
59
|
|
|
$file['routes']['upload'] |
60
|
|
|
); |
61
|
|
|
$uploadConfiguration[$key]['upload_strategy'] = $file['upload_strategy']; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
(new DownloadRoutesLoaderBuilder($container, $downloadConfiguration))->build(); |
65
|
|
|
(new GetFilesRoutesLoaderBuilder($container, $getFilesConfiguration))->build(); |
66
|
|
|
(new GetFileRoutesLoaderBuilder($container, $getFileConfiguration))->build(); |
67
|
|
|
(new UploadRoutesLoaderBuilder($container, $uploadConfiguration))->build(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|