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\SymfonyFilesystemBridgeBundle\DependencyInjection\Compiler; |
14
|
|
|
|
15
|
|
|
use BenGorFile\SymfonyFilesystemBridge\Infrastructure\Domain\Model\SymfonyFilesystem; |
16
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
19
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
20
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Register Symfony filesystem services compiler pass. |
24
|
|
|
* |
25
|
|
|
* Service declaration via PHP allows more |
26
|
|
|
* flexibility with customization extend files. |
27
|
|
|
* |
28
|
|
|
* @author Beñat Espiña <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class SymfonyFilesystemPass implements CompilerPassInterface |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
public function process(ContainerBuilder $container) |
36
|
|
|
{ |
37
|
|
|
$config = $container->getParameter('bengor_file.config'); |
38
|
|
|
foreach ($config['file_class'] as $key => $file) { |
39
|
|
|
if ('symfony' !== $file['storage']) { |
40
|
|
|
continue; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$container->setDefinition( |
44
|
|
|
'bengor.file.infrastructure.domain.model.' . $key . '_filesystem', |
45
|
|
|
new Definition( |
46
|
|
|
SymfonyFilesystem::class, [ |
47
|
|
|
$file['upload_destination'], |
48
|
|
|
new Reference('filesystem'), |
49
|
|
|
] |
50
|
|
|
) |
51
|
|
|
)->setPublic(false); |
52
|
|
|
|
53
|
|
|
$container->setAlias( |
54
|
|
|
'bengor_file.' . $key . '.filesystem', |
55
|
|
|
'bengor.file.infrastructure.domain.model.' . $key . '_filesystem' |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|