TableGuesser.php 903 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Illuminate\Database\Console\Migrations;
  3. class TableGuesser
  4. {
  5. const CREATE_PATTERNS = [
  6. '/^create_(\w+)_table$/',
  7. '/^create_(\w+)$/',
  8. ];
  9. const CHANGE_PATTERNS = [
  10. '/_(to|from|in)_(\w+)_table$/',
  11. '/_(to|from|in)_(\w+)$/',
  12. ];
  13. /**
  14. * Attempt to guess the table name and "creation" status of the given migration.
  15. *
  16. * @param string $migration
  17. * @return array
  18. */
  19. public static function guess($migration)
  20. {
  21. foreach (self::CREATE_PATTERNS as $pattern) {
  22. if (preg_match($pattern, $migration, $matches)) {
  23. return [$matches[1], $create = true];
  24. }
  25. }
  26. foreach (self::CHANGE_PATTERNS as $pattern) {
  27. if (preg_match($pattern, $migration, $matches)) {
  28. return [$matches[2], $create = false];
  29. }
  30. }
  31. }
  32. }