|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Bundle\MigrationsBundle\DependencyInjection; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\Config\FileLocator; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
10
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
11
|
|
|
use function count; |
|
12
|
|
|
use function current; |
|
13
|
|
|
use function key; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* DoctrineMigrationsExtension. |
|
17
|
|
|
*/ |
|
18
|
|
|
class DoctrineMigrationsExtension extends Extension |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* Responds to the migrations configuration parameter. |
|
22
|
|
|
* |
|
23
|
|
|
* @param string[][] $configs |
|
24
|
|
|
*/ |
|
25
|
2 |
|
public function load(array $configs, ContainerBuilder $container) : void |
|
26
|
|
|
{ |
|
27
|
2 |
|
$configuration = new Configuration(); |
|
28
|
|
|
|
|
29
|
2 |
|
$config = $this->processConfiguration($configuration, $configs); |
|
30
|
|
|
|
|
31
|
|
|
// 3.x forward compatibility layer |
|
32
|
2 |
|
if (isset($config['migrations_paths']) && count($config['migrations_paths'])>0) { |
|
33
|
1 |
|
$config['namespace'] = key($config['migrations_paths']); |
|
34
|
1 |
|
$config['dir_name'] = current($config['migrations_paths']); |
|
35
|
1 |
|
unset($config['migrations_paths']); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
2 |
|
if (isset($config['storage']['table_storage'])) { |
|
39
|
1 |
|
$storageConfig = $config['storage']['table_storage']; |
|
40
|
1 |
|
if (isset($storageConfig['table_name'])) { |
|
41
|
1 |
|
$config['table_name'] = $storageConfig['table_name']; |
|
42
|
|
|
} |
|
43
|
1 |
|
if (isset($storageConfig['version_column_name'])) { |
|
44
|
1 |
|
$config['column_name'] = $storageConfig['version_column_name']; |
|
45
|
|
|
} |
|
46
|
1 |
|
if (isset($storageConfig['version_column_length'])) { |
|
47
|
1 |
|
$config['column_length'] = $storageConfig['version_column_length']; |
|
48
|
|
|
} |
|
49
|
1 |
|
if (isset($storageConfig['executed_at_column_name'])) { |
|
50
|
1 |
|
$config['executed_at_column_name'] = $storageConfig['executed_at_column_name']; |
|
51
|
|
|
} |
|
52
|
1 |
|
unset($config['storage']); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
foreach ($config as $key => $value) { |
|
56
|
2 |
|
$container->setParameter($this->getAlias() . '.' . $key, $value); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
2 |
|
$locator = new FileLocator(__DIR__ . '/../Resources/config/'); |
|
60
|
2 |
|
$loader = new XmlFileLoader($container, $locator); |
|
61
|
|
|
|
|
62
|
2 |
|
$loader->load('services.xml'); |
|
63
|
2 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Returns the base path for the XSD files. |
|
67
|
|
|
* |
|
68
|
|
|
* @return string The XSD base path |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getXsdValidationBasePath() : string |
|
71
|
|
|
{ |
|
72
|
|
|
return __DIR__ . '/../Resources/config/schema'; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getNamespace() : string |
|
76
|
|
|
{ |
|
77
|
|
|
return 'http://symfony.com/schema/dic/doctrine/migrations'; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|