Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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