1 | <?php |
||
5 | class RuleParser |
||
6 | { |
||
7 | public static $columnTypes = [ |
||
8 | 'date', |
||
9 | 'dateTime', |
||
10 | 'decimal', |
||
11 | 'integer', |
||
12 | 'string', |
||
13 | 'text', |
||
14 | 'time', |
||
15 | 'timestamp', |
||
16 | 'unsigned', |
||
17 | ]; |
||
18 | |||
19 | /** |
||
20 | * Parse the rules to column creation methods |
||
21 | * |
||
22 | * @param $rules |
||
23 | * @return string |
||
24 | */ |
||
25 | public static function rulesToMigrationColumns(array $rules): string |
||
44 | |||
45 | /** |
||
46 | * Check if $rule contains any of the supported type |
||
47 | * WARNING: be aware of word length vs. word matching f.e. 'date' <-> 'dateTime' |
||
48 | * In that case the longest word should appear last in the array |
||
49 | * |
||
50 | * @param $rule |
||
51 | * @return mixed|string |
||
52 | */ |
||
53 | public static function getType($rule) |
||
63 | |||
64 | /** |
||
65 | * Parses the max:* rule |
||
66 | * |
||
67 | * @param $rule |
||
68 | * @return string |
||
69 | */ |
||
70 | public static function getMax($rule): string |
||
80 | |||
81 | /** |
||
82 | * Checks if column can be set to nullable |
||
83 | * |
||
84 | * @param $rule |
||
85 | * @return boolean |
||
86 | */ |
||
87 | public static function isRequired($rule): bool |
||
92 | |||
93 | /** |
||
94 | * Checks if columns needs to be set to unique |
||
95 | * |
||
96 | * @param $rule |
||
97 | * @return boolean |
||
98 | */ |
||
99 | public static function isUnique($rule): bool |
||
103 | |||
104 | /** |
||
105 | * Checks if columns is unsigned |
||
106 | * |
||
107 | * @param $rule |
||
108 | * @return boolean |
||
109 | */ |
||
110 | public static function isUnsigned($rule): bool |
||
114 | |||
115 | /** |
||
116 | * Checks if columns needs to be constructed as a foreign key |
||
117 | * |
||
118 | * @param $rule |
||
119 | * @return boolean |
||
120 | */ |
||
121 | public static function isForeign($rule): bool |
||
125 | |||
126 | private static function contains($rule, $needle): bool |
||
130 | } |
||
131 | |||
132 |