@@ -347,9 +347,8 @@ public function latestAll(string $group = null)
347347 $ this ->setGroup ($ group );
348348 }
349349
350- // Get all namespaces and their paths from the autoloader
351- $ autoloader = Services::autoloader (true );
352- $ namespaces = $ autoloader ->getNamespace ();
350+ // Get all namespaces from the autoloader
351+ $ namespaces = Services::autoloader ()->getNamespace ();
353352
354353 foreach ($ namespaces as $ namespace => $ paths )
355354 {
@@ -401,39 +400,30 @@ public function current(string $group = null)
401400 //--------------------------------------------------------------------
402401
403402 /**
404- * Retrieves list of available migration scripts
403+ * Retrieves list of available migration scripts for one namespace
405404 *
406405 * @return array list of migrations as $version for one namespace
407406 */
408407 public function findMigrations ()
409408 {
410409 $ migrations = [];
411- helper ('filesystem ' );
412410
413411 // If $this->path contains a valid directory use it.
414412 if (! empty ($ this ->path ))
415413 {
416- $ dirs = [rtrim ($ this ->path , DIRECTORY_SEPARATOR ) . '/ ' ];
414+ helper ('filesystem ' );
415+ $ dir = rtrim ($ this ->path , DIRECTORY_SEPARATOR ) . '/ ' ;
416+ $ files = get_filenames ($ dir , true );
417417 }
418- // Otherwise, get namespace location from the autoloader
419- // and add Database/Migrations for a standard location.
418+ // Otherwise use FileLocator to search files in the subdirectory of the namespace
420419 else
421420 {
422- // Get all namespaces and their paths from the autoloader
423- $ autoloader = Services::autoloader (true );
424- $ namespaces = $ autoloader ->getNamespace ();
425-
426- // Append the directory structure to each path in the namespace
427- foreach ($ namespaces [$ this ->namespace ] as $ path ) {
428- // Setting migration directories.
429- $ dir = rtrim ($ path , DIRECTORY_SEPARATOR ) . '/Database/Migrations/ ' ;
430- }
421+ $ locator = Services::locator (true );
422+ $ files = $ locator ->listNamespaceFiles ($ this ->namespace , '/Database/Migrations/ ' );
431423 }
432424
433425 // Load all *_*.php files in the migrations path
434426 // We can't use glob if we want it to be testable....
435- $ files = get_filenames ($ dir , true );
436-
437427 foreach ($ files as $ file )
438428 {
439429 if (substr ($ file , -4 ) !== '.php ' )
@@ -451,9 +441,9 @@ public function findMigrations()
451441 $ migration = new \stdClass ();
452442
453443 // Get migration version number
454- $ migration ->version = $ this ->getMigrationNumber ($ name );
455- $ migration ->name = $ this ->getMigrationName ($ name );
456- $ migration ->path = ! empty ($ this ->path ) && strpos ($ file , set_realpath ( $ 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
457447 ? $ this ->path . $ file
458448 : $ file ;
459449
0 commit comments