3636 * @filesource
3737 */
3838
39+ use Config \Services ;
3940use CodeIgniter \CLI \CLI ;
4041use CodeIgniter \Config \BaseConfig ;
4142use CodeIgniter \Exceptions \ConfigException ;
@@ -346,11 +347,10 @@ public function latestAll(string $group = null)
346347 $ this ->setGroup ($ group );
347348 }
348349
349- // Get all namespaces form PSR4 paths.
350- $ config = config ('Autoload ' );
351- $ namespaces = $ config ->psr4 ;
350+ // Get all namespaces from the autoloader
351+ $ namespaces = Services::autoloader ()->getNamespace ();
352352
353- foreach ($ namespaces as $ namespace => $ path )
353+ foreach ($ namespaces as $ namespace => $ paths )
354354 {
355355 $ this ->setNamespace ($ namespace );
356356 $ migrations = $ this ->findMigrations ();
@@ -400,36 +400,30 @@ public function current(string $group = null)
400400 //--------------------------------------------------------------------
401401
402402 /**
403- * Retrieves list of available migration scripts
403+ * Retrieves list of available migration scripts for one namespace
404404 *
405405 * @return array list of migrations as $version for one namespace
406406 */
407407 public function findMigrations ()
408408 {
409409 $ migrations = [];
410- helper ('filesystem ' );
411410
412411 // If $this->path contains a valid directory use it.
413412 if (! empty ($ this ->path ))
414413 {
414+ helper ('filesystem ' );
415415 $ dir = rtrim ($ this ->path , DIRECTORY_SEPARATOR ) . '/ ' ;
416+ $ files = get_filenames ($ dir , true );
416417 }
417- // Otherwise, get namespace location form PSR4 paths
418- // and add Database/Migrations for a standard location.
418+ // Otherwise use FileLocator to search files in the subdirectory of the namespace
419419 else
420420 {
421- $ config = config ('Autoload ' );
422-
423- $ location = $ config ->psr4 [$ this ->namespace ];
424-
425- // Setting migration directories.
426- $ dir = rtrim ($ location , DIRECTORY_SEPARATOR ) . '/Database/Migrations/ ' ;
421+ $ locator = Services::locator (true );
422+ $ files = $ locator ->listNamespaceFiles ($ this ->namespace , '/Database/Migrations/ ' );
427423 }
428424
429425 // Load all *_*.php files in the migrations path
430426 // We can't use glob if we want it to be testable....
431- $ files = get_filenames ($ dir , true );
432-
433427 foreach ($ files as $ file )
434428 {
435429 if (substr ($ file , -4 ) !== '.php ' )
@@ -447,9 +441,9 @@ public function findMigrations()
447441 $ migration = new \stdClass ();
448442
449443 // Get migration version number
450- $ migration ->version = $ this ->getMigrationNumber ($ name );
451- $ migration ->name = $ this ->getMigrationName ($ name );
452- $ migration ->path = ! empty ($ this ->path ) && strpos ($ file , $ this ->path ) !== 0
444+ $ migration ->version = $ this ->getMigrationNumber ($ name );
445+ $ migration ->name = $ this ->getMigrationName ($ name );
446+ $ migration ->path = ! empty ($ this ->path ) && strpos ($ file , $ this ->path ) !== 0
453447 ? $ this ->path . $ file
454448 : $ file ;
455449
0 commit comments