|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Bundle\MigrationsBundle\DependencyInjection; |
|
6
|
|
|
|
|
7
|
|
|
use ReflectionClass; |
|
8
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
9
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
10
|
|
|
use function array_filter; |
|
11
|
|
|
use function array_keys; |
|
12
|
|
|
use function constant; |
|
13
|
|
|
use function count; |
|
14
|
|
|
use function in_array; |
|
15
|
|
|
use function is_string; |
|
16
|
|
|
use function method_exists; |
|
17
|
|
|
use function strlen; |
|
18
|
|
|
use function strpos; |
|
19
|
|
|
use function strtoupper; |
|
20
|
|
|
use function substr; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* DoctrineMigrationsExtension configuration structure. |
|
24
|
|
|
*/ |
|
25
|
|
|
class Configuration implements ConfigurationInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Generates the configuration tree. |
|
29
|
|
|
* |
|
30
|
|
|
* @return TreeBuilder The config tree builder |
|
31
|
|
|
*/ |
|
32
|
26 |
|
public function getConfigTreeBuilder() : TreeBuilder |
|
33
|
|
|
{ |
|
34
|
26 |
|
$treeBuilder = new TreeBuilder('doctrine_migrations'); |
|
35
|
|
|
|
|
36
|
26 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
|
37
|
26 |
|
$rootNode = $treeBuilder->getRootNode(); |
|
38
|
|
|
} else { |
|
39
|
|
|
// BC layer for symfony/config 4.1 and older |
|
40
|
|
|
$rootNode = $treeBuilder->root('doctrine_migrations', 'array'); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
26 |
|
$organizeMigrationModes = $this->getOrganizeMigrationsModes(); |
|
44
|
|
|
|
|
45
|
|
|
$rootNode |
|
46
|
26 |
|
->fixXmlConfig('migration', 'migrations') |
|
47
|
26 |
|
->fixXmlConfig('migrations_path', 'migrations_paths') |
|
48
|
26 |
|
->children() |
|
49
|
26 |
|
->arrayNode('migrations_paths') |
|
50
|
26 |
|
->info('A list of namespace/path pairs where to look for migrations.') |
|
51
|
26 |
|
->defaultValue([]) |
|
52
|
26 |
|
->useAttributeAsKey('namespace') |
|
53
|
26 |
|
->prototype('scalar')->end() |
|
54
|
26 |
|
->end() |
|
55
|
|
|
|
|
56
|
26 |
|
->arrayNode('services') |
|
57
|
26 |
|
->info('A set of services to pass to the underlying doctrine/migrations library, allowing to change its behaviour.') |
|
58
|
26 |
|
->useAttributeAsKey('service') |
|
59
|
26 |
|
->defaultValue([]) |
|
60
|
26 |
|
->validate() |
|
61
|
|
|
->ifTrue(static function ($v) { |
|
62
|
|
|
return count(array_filter(array_keys($v), static function (string $doctrineService) : bool { |
|
63
|
4 |
|
return strpos($doctrineService, 'Doctrine\Migrations\\') !==0; |
|
64
|
4 |
|
})); |
|
65
|
26 |
|
}) |
|
66
|
26 |
|
->thenInvalid('Valid services for the DoctrineMigrationsBundle must be in the "Doctrine\Migrations" namespace.') |
|
67
|
26 |
|
->end() |
|
68
|
26 |
|
->prototype('scalar')->end() |
|
69
|
26 |
|
->end() |
|
70
|
|
|
|
|
71
|
26 |
|
->arrayNode('factories') |
|
72
|
26 |
|
->info('A set of callables to pass to the underlying doctrine/migrations library as services, allowing to change its behaviour.') |
|
73
|
26 |
|
->useAttributeAsKey('factory') |
|
74
|
26 |
|
->defaultValue([]) |
|
75
|
26 |
|
->validate() |
|
76
|
|
|
->ifTrue(static function ($v) { |
|
77
|
|
|
return count(array_filter(array_keys($v), static function (string $doctrineService) : bool { |
|
78
|
1 |
|
return strpos($doctrineService, 'Doctrine\Migrations\\') !==0; |
|
79
|
1 |
|
})); |
|
80
|
26 |
|
}) |
|
81
|
26 |
|
->thenInvalid('Valid callables for the DoctrineMigrationsBundle must be in the "Doctrine\Migrations" namespace.') |
|
82
|
26 |
|
->end() |
|
83
|
26 |
|
->prototype('scalar')->end() |
|
84
|
26 |
|
->end() |
|
85
|
|
|
|
|
86
|
26 |
|
->arrayNode('storage') |
|
87
|
26 |
|
->addDefaultsIfNotSet() |
|
88
|
26 |
|
->info('Storage to use for migration status metadata.') |
|
89
|
26 |
|
->children() |
|
90
|
26 |
|
->arrayNode('table_storage') |
|
91
|
26 |
|
->addDefaultsIfNotSet() |
|
92
|
26 |
|
->info('The default metadata storage, implemented as a table in the database.') |
|
93
|
26 |
|
->children() |
|
94
|
26 |
|
->scalarNode('table_name')->defaultValue(null)->cannotBeEmpty()->end() |
|
95
|
26 |
|
->scalarNode('version_column_name')->defaultValue(null)->end() |
|
96
|
26 |
|
->scalarNode('version_column_length')->defaultValue(null)->end() |
|
97
|
26 |
|
->scalarNode('executed_at_column_name')->defaultValue(null)->end() |
|
98
|
26 |
|
->scalarNode('execution_time_column_name')->defaultValue(null)->end() |
|
99
|
26 |
|
->end() |
|
100
|
26 |
|
->end() |
|
101
|
26 |
|
->end() |
|
102
|
26 |
|
->end() |
|
103
|
|
|
|
|
104
|
26 |
|
->arrayNode('migrations') |
|
105
|
26 |
|
->info('A list of migrations to load in addition to the one discovered via "migrations_paths".') |
|
106
|
26 |
|
->prototype('scalar')->end() |
|
107
|
26 |
|
->defaultValue([]) |
|
108
|
26 |
|
->end() |
|
109
|
26 |
|
->scalarNode('connection') |
|
110
|
26 |
|
->info('Connection name to use for the migrations database.') |
|
111
|
26 |
|
->defaultValue(null) |
|
112
|
26 |
|
->end() |
|
113
|
26 |
|
->scalarNode('em') |
|
114
|
26 |
|
->info('Entity manager name to use for the migrations database (available when doctrine/orm is installed).') |
|
115
|
26 |
|
->defaultValue(null) |
|
116
|
26 |
|
->end() |
|
117
|
26 |
|
->scalarNode('all_or_nothing') |
|
118
|
26 |
|
->info('Run all migrations in a transaction.') |
|
119
|
26 |
|
->defaultValue(false) |
|
120
|
26 |
|
->end() |
|
121
|
26 |
|
->scalarNode('check_database_platform') |
|
122
|
26 |
|
->info('Adds an extra check in the generated migrations to allow execution only on the same platform as they were initially generated on.') |
|
123
|
26 |
|
->defaultValue(true) |
|
124
|
26 |
|
->end() |
|
125
|
26 |
|
->scalarNode('custom_template') |
|
126
|
26 |
|
->info('Custom template path for generated migration classes.') |
|
127
|
26 |
|
->defaultValue(null) |
|
128
|
26 |
|
->end() |
|
129
|
26 |
|
->scalarNode('organize_migrations') |
|
130
|
26 |
|
->defaultValue(false) |
|
131
|
26 |
|
->info('Organize migrations mode. Possible values are: "BY_YEAR", "BY_YEAR_AND_MONTH", false') |
|
132
|
26 |
|
->validate() |
|
133
|
|
|
->ifTrue(static function ($v) use ($organizeMigrationModes) { |
|
134
|
2 |
|
if ($v === false) { |
|
135
|
|
|
return false; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
2 |
|
if (is_string($v) && in_array(strtoupper($v), $organizeMigrationModes, true)) { |
|
139
|
2 |
|
return false; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
return true; |
|
143
|
26 |
|
}) |
|
144
|
26 |
|
->thenInvalid('Invalid organize migrations mode value %s') |
|
145
|
26 |
|
->end() |
|
146
|
26 |
|
->validate() |
|
147
|
26 |
|
->ifString() |
|
148
|
|
|
->then(static function ($v) { |
|
149
|
2 |
|
return constant('Doctrine\Migrations\Configuration\Configuration::VERSIONS_ORGANIZATION_' . strtoupper($v)); |
|
150
|
26 |
|
}) |
|
151
|
26 |
|
->end() |
|
152
|
26 |
|
->end() |
|
153
|
26 |
|
->end(); |
|
154
|
|
|
|
|
155
|
26 |
|
return $treeBuilder; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Find organize migrations modes for their names |
|
161
|
|
|
* |
|
162
|
|
|
* @return string[] |
|
163
|
|
|
*/ |
|
164
|
26 |
|
private function getOrganizeMigrationsModes() : array |
|
165
|
|
|
{ |
|
166
|
26 |
|
$constPrefix = 'VERSIONS_ORGANIZATION_'; |
|
167
|
26 |
|
$prefixLen = strlen($constPrefix); |
|
168
|
26 |
|
$refClass = new ReflectionClass('Doctrine\Migrations\Configuration\Configuration'); |
|
169
|
26 |
|
$constsArray = $refClass->getConstants(); |
|
170
|
26 |
|
$namesArray = []; |
|
171
|
|
|
|
|
172
|
26 |
|
foreach ($constsArray as $key => $value) { |
|
173
|
26 |
|
if (strpos($key, $constPrefix) !== 0) { |
|
174
|
|
|
continue; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
26 |
|
$namesArray[] = substr($key, $prefixLen); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
26 |
|
return $namesArray; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.