1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrs\SonataImportBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
6
|
|
|
use Symfony\Component\Config\FileLocator; |
7
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* This is the class that loads and manages your bundle configuration |
12
|
|
|
* |
13
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
14
|
|
|
*/ |
15
|
|
|
class DoctrsSonataImportExtension extends Extension |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
public function load(array $configs, ContainerBuilder $container) |
21
|
|
|
{ |
22
|
|
|
$configuration = new Configuration(); |
23
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
24
|
|
|
$this->prepairConfig($config, $container); |
25
|
|
|
|
26
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
27
|
|
|
$loader->load('services.xml'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param array $config |
32
|
|
|
* @param ContainerBuilder $container |
33
|
|
|
*/ |
34
|
|
|
private function prepairConfig(array $config, ContainerBuilder $container){ |
35
|
|
|
$config['mappings'] = array_merge($config['mappings'], [[ |
36
|
|
|
'name' => 'date', |
37
|
|
|
'class' => 'doctrs.type.datetime' |
38
|
|
|
],[ |
39
|
|
|
'name' => 'datetime', |
40
|
|
|
'class' => 'doctrs.type.datetime' |
41
|
|
|
],[ |
42
|
|
|
'name' => 'boolean', |
43
|
|
|
'class' => 'doctrs.type.boolean' |
44
|
|
|
],[ |
45
|
|
|
'name' => 'integer', |
46
|
|
|
'class' => 'doctrs.type.integer' |
47
|
|
|
],[ |
48
|
|
|
'name' => 'entity', |
49
|
|
|
'class' => 'doctrs.type.entity' |
50
|
|
|
],[ |
51
|
|
|
'name' => 'choice', |
52
|
|
|
'class' => 'doctrs.type.entity' |
53
|
|
|
]]); |
54
|
|
|
$container->setParameter( |
55
|
|
|
'doctrs_sonata_import.mappings', |
56
|
|
|
$config['mappings'] |
57
|
|
|
); |
58
|
|
|
$container->setParameter( |
59
|
|
|
'doctrs_sonata_import.upload_dir', |
60
|
|
|
$config['upload_dir'] ? $config['upload_dir'] : $container->get('kernel')->getRootDir() . '/../web/uploads' |
61
|
|
|
); |
62
|
|
|
$container->setParameter( |
63
|
|
|
'doctrs_sonata_import.class_loaders', |
64
|
|
|
$config['class_loaders'] |
65
|
|
|
); |
66
|
|
|
if (!isset($config['encode'])) { |
67
|
|
|
$config['encode'] = [ |
68
|
|
|
'default' => 'utf8', |
69
|
|
|
'list' => [] |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
$container->setParameter( |
73
|
|
|
'doctrs_sonata_import.encode.default', |
74
|
|
|
$config['encode']['default'] |
75
|
|
|
); |
76
|
|
|
$container->setParameter( |
77
|
|
|
'doctrs_sonata_import.encode.list', |
78
|
|
|
$config['encode']['list'] |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|