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\DoctrineORMBridgeBundle\DependencyInjection\Compiler; |
14
|
|
|
|
15
|
|
|
use BenGorFile\DoctrineORMBridge\Infrastructure\Persistence\DoctrineORMFileRepository; |
16
|
|
|
use BenGorFile\DoctrineORMBridge\Infrastructure\Persistence\DoctrineORMFileSpecificationFactory; |
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
20
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Register Doctrine ORM 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 DoctrineORMServicesPass 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 ('doctrine_orm' !== $file['persistence']) { |
40
|
|
|
continue; |
41
|
|
|
} |
42
|
|
|
$container->setDefinition( |
43
|
|
|
'bengor.file.infrastructure.persistence.' . $key . '_specification_factory', |
44
|
|
|
(new Definition( |
45
|
|
|
DoctrineORMFileSpecificationFactory::class |
46
|
|
|
))->setPublic(false) |
47
|
|
|
); |
48
|
|
|
$container->setAlias( |
49
|
|
|
'bengor_file.' . $key . '.specification_factory', |
50
|
|
|
'bengor.file.infrastructure.persistence.' . $key . '_specification_factory' |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
$container->setDefinition( |
54
|
|
|
'bengor.file.infrastructure.persistence.' . $key . '_repository', |
55
|
|
|
(new Definition( |
56
|
|
|
DoctrineORMFileRepository::class, [ |
57
|
|
|
$file['class'], |
58
|
|
|
] |
59
|
|
|
))->setFactory([ |
60
|
|
|
new Reference('doctrine.orm.default_entity_manager'), 'getRepository', |
61
|
|
|
])->setPublic(false) |
62
|
|
|
); |
63
|
|
|
$container->setAlias( |
64
|
|
|
'bengor_file.' . $key . '.repository', |
65
|
|
|
'bengor.file.infrastructure.persistence.' . $key . '_repository' |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|