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 | ]; |
||
17 | |||
18 | /** |
||
19 | * Parse the rules to column creation methods |
||
20 | * |
||
21 | * @param $rules |
||
22 | * @return string |
||
23 | */ |
||
24 | public static function rulesToMigrationColumns(array $rules): string |
||
42 | |||
43 | /** |
||
44 | * Fill the $fillable, mostly for cosmetics |
||
45 | * |
||
46 | * @param $rules |
||
47 | * @return string |
||
48 | */ |
||
49 | public static function rulesToFillables($rules): string |
||
69 | |||
70 | /** |
||
71 | * Check if $rule contains any of the supported type |
||
72 | * WARNING: be aware of word length vs. word matching f.e. 'date' <-> 'dateTime' |
||
73 | * In that case the longest word should appear last in the array |
||
74 | * |
||
75 | * @param $rule |
||
76 | * @return mixed|string |
||
77 | */ |
||
78 | public static function getType($rule) |
||
88 | |||
89 | /** |
||
90 | * Parses the max:* rule |
||
91 | * |
||
92 | * @param $rule |
||
93 | * @return string |
||
94 | */ |
||
95 | public static function getMax($rule): string |
||
105 | |||
106 | /** |
||
107 | * Checks if column can be set to nullable |
||
108 | * |
||
109 | * @param $rule |
||
110 | * @return boolean |
||
111 | */ |
||
112 | public static function isRequired($rule): bool |
||
117 | |||
118 | /** |
||
119 | * Checks if columns needs to be set to unique |
||
120 | * |
||
121 | * @param $rule |
||
122 | * @return boolean |
||
123 | */ |
||
124 | public static function isUnique($rule): bool |
||
128 | |||
129 | private static function contains($rule, $needle): bool |
||
133 | } |
||
134 | |||
135 |