@@ -27,22 +27,70 @@ class Configuration implements ConfigurationInterface
2727 /**
2828 * Generates the configuration tree.
2929 *
30- * @return \Symfony\Component\Config\Definition\Builder\ TreeBuilder The config tree builder
30+ * @return TreeBuilder The config tree builder
3131 */
3232 public function getConfigTreeBuilder ()
3333 {
3434 $ treeBuilder = new TreeBuilder ();
3535 $ rootNode = $ treeBuilder ->root ('doctrine_migrations ' , 'array ' );
3636
37+ $ organizeMigrationModes = $ this ->getOrganizeMigrationsModes ();
38+
3739 $ rootNode
3840 ->children ()
3941 ->scalarNode ('dir_name ' )->defaultValue ('%kernel.root_dir%/DoctrineMigrations ' )->cannotBeEmpty ()->end ()
4042 ->scalarNode ('namespace ' )->defaultValue ('Application\Migrations ' )->cannotBeEmpty ()->end ()
4143 ->scalarNode ('table_name ' )->defaultValue ('migration_versions ' )->cannotBeEmpty ()->end ()
4244 ->scalarNode ('name ' )->defaultValue ('Application Migrations ' )->end ()
45+ ->scalarNode ('organize_migrations ' )->defaultValue (false )
46+ ->info ('Organize migrations mode. Possible values are: "BY_YEAR", "BY_YEAR_AND_MONTH", false ' )
47+ ->validate ()
48+ ->ifTrue (function ($ v ) use ($ organizeMigrationModes ) {
49+ if (false === $ v ) {
50+ return false ;
51+ }
52+
53+ if (is_string ($ v ) && in_array (strtoupper ($ v ), $ organizeMigrationModes )) {
54+ return false ;
55+ }
56+
57+ return true ;
58+ })
59+ ->thenInvalid ('Invalid organize migrations mode value %s ' )
60+ ->end ()
61+ ->validate ()
62+ ->ifString ()
63+ ->then (function ($ v ) {
64+ return constant ('Doctrine\DBAL\Migrations\Configuration\Configuration::VERSIONS_ORGANIZATION_ ' .strtoupper ($ v ));
65+ })
66+ ->end ()
67+ ->end ()
4368 ->end ()
4469 ;
4570
4671 return $ treeBuilder ;
4772 }
73+
74+
75+ /**
76+ * Find organize migrations modes for their names
77+ *
78+ * @return array
79+ */
80+ private function getOrganizeMigrationsModes ()
81+ {
82+ $ constPrefix = 'VERSIONS_ORGANIZATION_ ' ;
83+ $ prefixLen = strlen ($ constPrefix );
84+ $ refClass = new \ReflectionClass ('Doctrine\DBAL\Migrations\Configuration\Configuration ' );
85+ $ constsArray = $ refClass ->getConstants ();
86+ $ namesArray = array ();
87+
88+ foreach ($ constsArray as $ key => $ value ) {
89+ if (strpos ($ key , $ constPrefix ) === 0 ) {
90+ $ namesArray [] = substr ($ key , $ prefixLen );
91+ }
92+ }
93+
94+ return $ namesArray ;
95+ }
4896}
0 commit comments