|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Doctrine; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
|
15
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\Form\Builder\DefaultFormBuilder; |
|
16
|
|
|
use Sylius\Bundle\ResourceBundle\Form\Type\DefaultResourceType; |
|
17
|
|
|
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; |
|
18
|
|
|
use Sylius\Component\Resource\Metadata\MetadataInterface; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
25
|
|
|
* @author Arnaud Langlade <[email protected]> |
|
26
|
|
|
* @author Gonzalo Vilaseca <[email protected]> |
|
27
|
|
|
*/ |
|
28
|
|
|
final class DoctrineORMDriver extends AbstractDoctrineDriver |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getType() |
|
34
|
|
|
{ |
|
35
|
|
|
return SyliusResourceBundle::DRIVER_DOCTRINE_ORM; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function addRepository(ContainerBuilder $container, MetadataInterface $metadata) |
|
42
|
|
|
{ |
|
43
|
|
|
$repositoryClassParameterName = sprintf('%s.repository.%s.class', $metadata->getApplicationName(), $metadata->getName()); |
|
44
|
|
|
$repositoryClass = EntityRepository::class; |
|
45
|
|
|
|
|
46
|
|
|
if ($container->hasParameter($repositoryClassParameterName)) { |
|
47
|
|
|
$repositoryClass = $container->getParameter($repositoryClassParameterName); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if ($metadata->hasClass('repository')) { |
|
51
|
|
|
$repositoryClass = $metadata->getClass('repository'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
$definition = new Definition($repositoryClass); |
|
55
|
|
|
$definition->setArguments([ |
|
56
|
|
|
new Reference($metadata->getServiceId('manager')), |
|
57
|
|
|
$this->getClassMetadataDefinition($metadata), |
|
58
|
|
|
]); |
|
59
|
|
|
|
|
60
|
|
|
$container->setDefinition($metadata->getServiceId('repository'), $definition); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritdoc} |
|
65
|
|
|
*/ |
|
66
|
|
|
protected function getManagerServiceId(MetadataInterface $metadata) |
|
67
|
|
|
{ |
|
68
|
|
|
if ($objectManagerName = $this->getObjectManagerName($metadata)) { |
|
69
|
|
|
return sprintf('doctrine.orm.%s_entity_manager', $objectManagerName); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return 'doctrine.orm.entity_manager'; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* {@inheritdoc} |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function getClassMetadataClassname() |
|
79
|
|
|
{ |
|
80
|
|
|
return 'Doctrine\\ORM\\Mapping\\ClassMetadata'; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|