|
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\TaxonomyBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension; |
|
15
|
|
|
use Sylius\Component\Resource\Factory\Factory; |
|
16
|
|
|
use Sylius\Component\Translation\Factory\TranslatableFactory; |
|
17
|
|
|
use Symfony\Component\Config\FileLocator; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\Parameter; |
|
22
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class SyliusTaxonomyExtension extends AbstractResourceExtension |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function load(array $config, ContainerBuilder $container) |
|
33
|
|
|
{ |
|
34
|
|
|
$config = $this->processConfiguration(new Configuration(), $config); |
|
35
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
36
|
|
|
|
|
37
|
|
|
$loader->load(sprintf('driver/%s.xml', $config['driver'])); |
|
38
|
|
|
|
|
39
|
|
|
$this->registerResources('sylius', $config['driver'], $config['resources'], $container); |
|
40
|
|
|
|
|
41
|
|
|
$configFiles = array( |
|
42
|
|
|
'services.xml', |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
foreach ($configFiles as $configFile) { |
|
46
|
|
|
$loader->load($configFile); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$factoryDefinition = new Definition(Factory::class); |
|
50
|
|
|
$factoryDefinition->setArguments( |
|
51
|
|
|
array( |
|
52
|
|
|
new Parameter('sylius.model.taxonomy.class') |
|
53
|
|
|
) |
|
54
|
|
|
); |
|
55
|
|
|
|
|
56
|
|
|
$translatableFactoryDefinition = $container->getDefinition('sylius.factory.taxonomy'); |
|
57
|
|
|
$taxonomyFactoryClass = $translatableFactoryDefinition->getClass(); |
|
58
|
|
|
$translatableFactoryDefinition->setClass(TranslatableFactory::class); |
|
59
|
|
|
$translatableFactoryDefinition->setArguments( |
|
60
|
|
|
array( |
|
61
|
|
|
$factoryDefinition, |
|
62
|
|
|
new Reference('sylius.translation.locale_provider') |
|
63
|
|
|
) |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
$decoratedTaxonomyFactoryDefinition = new Definition($taxonomyFactoryClass); |
|
67
|
|
|
$decoratedTaxonomyFactoryDefinition->setArguments( |
|
68
|
|
|
array( |
|
69
|
|
|
$translatableFactoryDefinition, |
|
70
|
|
|
new Reference('sylius.factory.taxon') |
|
71
|
|
|
) |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$container->setDefinition('sylius.factory.taxonomy', $decoratedTaxonomyFactoryDefinition); |
|
75
|
|
|
|
|
76
|
|
|
$taxonFactoryDefinition = $container->getDefinition('sylius.factory.taxon'); |
|
77
|
|
|
$taxonFactoryClass = $taxonFactoryDefinition->getClass(); |
|
78
|
|
|
$taxonFactoryDefinition->setClass(TranslatableFactory::class); |
|
79
|
|
|
|
|
80
|
|
|
$decoratedTaxonFactoryDefinition = new Definition($taxonFactoryClass); |
|
81
|
|
|
$decoratedTaxonFactoryDefinition |
|
82
|
|
|
->addArgument($taxonFactoryDefinition) |
|
83
|
|
|
->addArgument(new Reference('sylius.repository.taxonomy')) |
|
84
|
|
|
; |
|
85
|
|
|
$container->setDefinition('sylius.factory.taxon', $decoratedTaxonFactoryDefinition); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|