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