|
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 constant; |
|
11
|
|
|
use function in_array; |
|
12
|
|
|
use function is_string; |
|
13
|
|
|
use function method_exists; |
|
14
|
|
|
use function strlen; |
|
15
|
|
|
use function strpos; |
|
16
|
|
|
use function strtoupper; |
|
17
|
|
|
use function substr; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* DoctrineMigrationsExtension configuration structure. |
|
21
|
|
|
*/ |
|
22
|
|
|
class Configuration implements ConfigurationInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Generates the configuration tree. |
|
26
|
|
|
* |
|
27
|
|
|
* @return TreeBuilder The config tree builder |
|
28
|
|
|
*/ |
|
29
|
1 |
|
public function getConfigTreeBuilder() : TreeBuilder |
|
30
|
|
|
{ |
|
31
|
1 |
|
$treeBuilder = new TreeBuilder('doctrine_migrations'); |
|
32
|
|
|
|
|
33
|
1 |
|
if (method_exists($treeBuilder, 'getRootNode')) { |
|
34
|
1 |
|
$rootNode = $treeBuilder->getRootNode(); |
|
35
|
|
|
} else { |
|
36
|
|
|
// BC layer for symfony/config 4.1 and older |
|
37
|
|
|
$rootNode = $treeBuilder->root('doctrine_migrations', 'array'); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
$organizeMigrationModes = $this->getOrganizeMigrationsModes(); |
|
41
|
|
|
|
|
42
|
|
|
$rootNode |
|
43
|
1 |
|
->children() |
|
44
|
1 |
|
->scalarNode('dir_name')->defaultValue('%kernel.root_dir%/DoctrineMigrations')->cannotBeEmpty()->end() |
|
45
|
1 |
|
->scalarNode('namespace')->defaultValue('Application\Migrations')->cannotBeEmpty()->end() |
|
46
|
1 |
|
->scalarNode('table_name')->defaultValue('migration_versions')->cannotBeEmpty()->end() |
|
47
|
1 |
|
->scalarNode('column_name')->defaultValue('version')->end() |
|
48
|
1 |
|
->scalarNode('column_length')->defaultValue(14)->end() |
|
49
|
1 |
|
->scalarNode('executed_at_column_name')->defaultValue('executed_at')->end() |
|
50
|
1 |
|
->scalarNode('all_or_nothing')->defaultValue(false)->end() |
|
51
|
1 |
|
->scalarNode('name')->defaultValue('Application Migrations')->end() |
|
52
|
1 |
|
->scalarNode('custom_template')->defaultValue(null)->end() |
|
53
|
1 |
|
->scalarNode('check_database_platform')->defaultValue(true)->end() |
|
54
|
1 |
|
->scalarNode('organize_migrations')->defaultValue(false) |
|
55
|
1 |
|
->info('Organize migrations mode. Possible values are: "BY_YEAR", "BY_YEAR_AND_MONTH", false') |
|
56
|
1 |
|
->validate() |
|
57
|
|
|
->ifTrue(static function ($v) use ($organizeMigrationModes) { |
|
58
|
1 |
|
if ($v === false) { |
|
59
|
|
|
return false; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
if (is_string($v) && in_array(strtoupper($v), $organizeMigrationModes)) { |
|
63
|
1 |
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return true; |
|
67
|
1 |
|
}) |
|
68
|
1 |
|
->thenInvalid('Invalid organize migrations mode value %s') |
|
69
|
1 |
|
->end() |
|
70
|
1 |
|
->validate() |
|
71
|
1 |
|
->ifString() |
|
72
|
|
|
->then(static function ($v) { |
|
73
|
1 |
|
return constant('Doctrine\Migrations\Configuration\Configuration::VERSIONS_ORGANIZATION_' . strtoupper($v)); |
|
74
|
1 |
|
}) |
|
75
|
1 |
|
->end() |
|
76
|
1 |
|
->end() |
|
77
|
1 |
|
->end(); |
|
78
|
|
|
|
|
79
|
1 |
|
return $treeBuilder; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Find organize migrations modes for their names |
|
85
|
|
|
* |
|
86
|
|
|
* @return string[] |
|
87
|
|
|
*/ |
|
88
|
1 |
|
private function getOrganizeMigrationsModes() : array |
|
89
|
|
|
{ |
|
90
|
1 |
|
$constPrefix = 'VERSIONS_ORGANIZATION_'; |
|
91
|
1 |
|
$prefixLen = strlen($constPrefix); |
|
92
|
1 |
|
$refClass = new ReflectionClass('Doctrine\Migrations\Configuration\Configuration'); |
|
93
|
1 |
|
$constsArray = $refClass->getConstants(); |
|
94
|
1 |
|
$namesArray = []; |
|
95
|
|
|
|
|
96
|
1 |
|
foreach ($constsArray as $key => $value) { |
|
97
|
1 |
|
if (strpos($key, $constPrefix) !== 0) { |
|
98
|
1 |
|
continue; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
$namesArray[] = substr($key, $prefixLen); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
1 |
|
return $namesArray; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.