13
13
use Symfony \Component \DependencyInjection \ContainerInterface ;
14
14
use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
15
15
16
+ use function assert ;
16
17
use function error_get_last ;
18
+ use function is_bool ;
17
19
use function is_dir ;
20
+ use function is_int ;
21
+ use function is_string ;
18
22
use function mkdir ;
19
23
use function preg_match ;
20
24
use function preg_quote ;
@@ -31,7 +35,7 @@ public static function configureMigrations(ContainerInterface $container, Config
31
35
$ dir = $ configuration ->getMigrationsDirectory ();
32
36
33
37
if ($ dir === null ) {
34
- $ dir = $ container-> getParameter ( 'doctrine_migrations.dir_name ' );
38
+ $ dir = self :: getStringParameter ( $ container, 'doctrine_migrations.dir_name ' );
35
39
36
40
if (! is_dir ($ dir ) && ! @mkdir ($ dir , 0777 , true ) && ! is_dir ($ dir )) {
37
41
$ error = error_get_last ();
@@ -53,7 +57,10 @@ public static function configureMigrations(ContainerInterface $container, Config
53
57
continue ;
54
58
}
55
59
56
- $ dir = str_replace ('% ' . $ pathPlaceholder . '% ' , $ container ->getParameter ($ pathPlaceholder ), $ dir );
60
+ $ dir = str_replace ('% ' . $ pathPlaceholder . '% ' , self ::getStringParameter (
61
+ $ container ,
62
+ $ pathPlaceholder
63
+ ), $ dir );
57
64
}
58
65
59
66
if (! is_dir ($ dir ) && ! @mkdir ($ dir , 0777 , true ) && ! is_dir ($ dir )) {
@@ -70,22 +77,32 @@ public static function configureMigrations(ContainerInterface $container, Config
70
77
}
71
78
72
79
if ($ configuration ->getMigrationsNamespace () === null ) {
73
- $ configuration ->setMigrationsNamespace ($ container ->getParameter ('doctrine_migrations.namespace ' ));
80
+ $ configuration ->setMigrationsNamespace (self ::getStringParameter (
81
+ $ container ,
82
+ 'doctrine_migrations.namespace '
83
+ ));
74
84
}
75
85
76
86
if ($ configuration ->getName () === null ) {
77
- $ configuration ->setName ($ container ->getParameter ('doctrine_migrations.name ' ));
87
+ $ configuration ->setName (self ::getStringParameter (
88
+ $ container ,
89
+ 'doctrine_migrations.name '
90
+ ));
78
91
}
79
92
80
93
// For backward compatibility, need use a table from parameters for overwrite the default configuration
81
94
if (! ($ configuration instanceof AbstractFileConfiguration) || $ configuration ->getMigrationsTableName () === '' ) {
82
- $ configuration ->setMigrationsTableName ($ container-> getParameter ( 'doctrine_migrations.table_name ' ));
95
+ $ configuration ->setMigrationsTableName (self :: getStringParameter ( $ container, 'doctrine_migrations.table_name ' ));
83
96
}
84
97
85
- $ configuration ->setMigrationsColumnName ($ container ->getParameter ('doctrine_migrations.column_name ' ));
86
- $ configuration ->setMigrationsColumnLength ($ container ->getParameter ('doctrine_migrations.column_length ' ));
87
- $ configuration ->setMigrationsExecutedAtColumnName ($ container ->getParameter ('doctrine_migrations.executed_at_column_name ' ));
88
- $ configuration ->setAllOrNothing ($ container ->getParameter ('doctrine_migrations.all_or_nothing ' ));
98
+ $ configuration ->setMigrationsColumnName (self ::getStringParameter ($ container , 'doctrine_migrations.column_name ' ));
99
+ $ columnLength = $ container ->getParameter ('doctrine_migrations.column_length ' );
100
+ assert (is_int ($ columnLength ));
101
+ $ configuration ->setMigrationsColumnLength ($ columnLength );
102
+ $ configuration ->setMigrationsExecutedAtColumnName (self ::getStringParameter ($ container , 'doctrine_migrations.executed_at_column_name ' ));
103
+ $ allOrNothing = $ container ->getParameter ('doctrine_migrations.all_or_nothing ' );
104
+ assert (is_bool ($ allOrNothing ));
105
+ $ configuration ->setAllOrNothing ($ allOrNothing );
89
106
90
107
// Migrations is not register from configuration loader
91
108
if (! ($ configuration instanceof AbstractFileConfiguration)) {
@@ -97,7 +114,9 @@ public static function configureMigrations(ContainerInterface $container, Config
97
114
}
98
115
99
116
if ($ configuration ->getCustomTemplate () === null ) {
100
- $ configuration ->setCustomTemplate ($ container ->getParameter ('doctrine_migrations.custom_template ' ));
117
+ $ customTemplate = $ container ->getParameter ('doctrine_migrations.custom_template ' );
118
+ assert (is_string ($ customTemplate ) || $ customTemplate === null );
119
+ $ configuration ->setCustomTemplate ($ customTemplate );
101
120
}
102
121
103
122
$ organizeMigrations = $ container ->getParameter ('doctrine_migrations.organize_migrations ' );
@@ -137,4 +156,12 @@ private static function injectContainerToMigrations(ContainerInterface $containe
137
156
$ migration ->setContainer ($ container );
138
157
}
139
158
}
159
+
160
+ private static function getStringParameter (ContainerInterface $ container , string $ name ): string
161
+ {
162
+ $ value = $ container ->getParameter ($ name );
163
+ assert (is_string ($ value ));
164
+
165
+ return $ value ;
166
+ }
140
167
}
0 commit comments