@@ -67,7 +67,7 @@ class MigrationRunner
6767 *
6868 * @var string
6969 */
70- protected $ regex = '/^\ d{4}[_-]?\d{2}[_-]?\d{2}[_-]?\d{6}_(\w+)$ / ' ;
70+ protected $ regex = '/\A(\ d{4}[_-]?\d{2}[_-]?\d{2}[_-]?\d{6}) _(\w+)\z / ' ;
7171
7272 /**
7373 * The main database connection. Used to store
@@ -448,6 +448,8 @@ public function findNamespaceMigrations(string $namespace): array
448448 /**
449449 * Create a migration object from a file path.
450450 *
451+ * @param string $path Full path to a valid migration file.
452+ *
451453 * @return false|object Returns the migration object, or false on failure
452454 */
453455 protected function migrationFromFile (string $ path , string $ namespace )
@@ -456,18 +458,18 @@ protected function migrationFromFile(string $path, string $namespace)
456458 return false ;
457459 }
458460
459- $ name = basename ($ path , '.php ' );
461+ $ filename = basename ($ path , '.php ' );
460462
461- if (! preg_match ($ this ->regex , $ name )) {
463+ if (! preg_match ($ this ->regex , $ filename )) {
462464 return false ;
463465 }
464466
465467 $ locator = Services::locator (true );
466468
467469 $ migration = new stdClass ();
468470
469- $ migration ->version = $ this ->getMigrationNumber ($ name );
470- $ migration ->name = $ this ->getMigrationName ($ name );
471+ $ migration ->version = $ this ->getMigrationNumber ($ filename );
472+ $ migration ->name = $ this ->getMigrationName ($ filename );
471473 $ migration ->path = $ path ;
472474 $ migration ->class = $ locator ->getClassname ($ path );
473475 $ migration ->namespace = $ namespace ;
@@ -525,23 +527,29 @@ public function setSilent(bool $silent)
525527
526528 /**
527529 * Extracts the migration number from a filename
530+ *
531+ * @param string $migration A migration filename w/o path.
528532 */
529533 protected function getMigrationNumber (string $ migration ): string
530534 {
531- preg_match (' /^\d{4}[_-]?\d{2}[_-]?\d{2}[_-]?\d{6}/ ' , $ migration , $ matches );
535+ preg_match ($ this -> regex , $ migration , $ matches );
532536
533- return count ($ matches ) ? $ matches [0 ] : '0 ' ;
537+ return count ($ matches ) ? $ matches [1 ] : '0 ' ;
534538 }
535539
536540 /**
537- * Extracts the migration class name from a filename
541+ * Extracts the migration name from a filename
542+ *
543+ * Note: The migration name should be the classname, but maybe they are
544+ * different.
545+ *
546+ * @param string $migration A migration filename w/o path.
538547 */
539548 protected function getMigrationName (string $ migration ): string
540549 {
541- $ parts = explode ('_ ' , $ migration );
542- array_shift ($ parts );
550+ preg_match ($ this ->regex , $ migration , $ matches );
543551
544- return implode ( ' _ ' , $ parts ) ;
552+ return count ( $ matches ) ? $ matches [ 2 ] : '' ;
545553 }
546554
547555 /**
0 commit comments