1 | <?php |
||
5 | class RuleParser |
||
6 | { |
||
7 | public static $types = [ |
||
8 | 'boolean', |
||
9 | 'dateTime', |
||
10 | 'date', |
||
11 | 'decimal', |
||
12 | 'dropColumn', |
||
13 | 'integer', |
||
14 | 'increments', |
||
15 | 'renameColumn', |
||
16 | 'string', |
||
17 | 'text', |
||
18 | 'timestamp', |
||
19 | 'time', |
||
20 | 'unsigned', |
||
21 | ]; |
||
22 | |||
23 | /** |
||
24 | * Parse the rules to column creation methods |
||
25 | * |
||
26 | * @param $fields |
||
27 | * @return string |
||
28 | */ |
||
29 | public static function fieldsToMigrationMethods(array $fields): string |
||
48 | |||
49 | /** |
||
50 | * @param $rule |
||
51 | * @return string |
||
52 | */ |
||
53 | public static function getAdditionalUpMethods($rule): string |
||
63 | |||
64 | /** |
||
65 | * Check if $rule contains any of the supported type |
||
66 | * WARNING: be aware of word length vs. word matching f.e. 'date' <-> 'dateTime' |
||
67 | * In that case the longest word should appear last in the array |
||
68 | * |
||
69 | * @param $rule |
||
70 | * @return mixed|string |
||
71 | */ |
||
72 | public static function getType($rule) |
||
82 | |||
83 | /** |
||
84 | * Parses the max:* rule |
||
85 | * |
||
86 | * @param $rule |
||
87 | * @return string |
||
88 | */ |
||
89 | public static function getMax($rule): string |
||
99 | |||
100 | /** |
||
101 | * Gets old name for renaming column |
||
102 | * |
||
103 | * @param $rule |
||
104 | * @return string |
||
105 | */ |
||
106 | public static function getRenameFrom($rule): string |
||
120 | |||
121 | /** |
||
122 | * Checks if column can be set to nullable |
||
123 | * |
||
124 | * @param $rule |
||
125 | * @return boolean |
||
126 | */ |
||
127 | public static function isRequired($rule): bool |
||
133 | |||
134 | /** |
||
135 | * Checks if columns needs to be set to unique |
||
136 | * |
||
137 | * @param $rule |
||
138 | * @return boolean |
||
139 | */ |
||
140 | public static function isIncrements($rule): bool |
||
144 | |||
145 | /** |
||
146 | * Checks if columns needs to be set to unique |
||
147 | * |
||
148 | * @param $rule |
||
149 | * @return boolean |
||
150 | */ |
||
151 | public static function isUnique($rule): bool |
||
155 | |||
156 | /** |
||
157 | * Checks if columns is unsigned |
||
158 | * |
||
159 | * @param $rule |
||
160 | * @return boolean |
||
161 | */ |
||
162 | public static function isUnsigned($rule): bool |
||
167 | |||
168 | |||
169 | /** |
||
170 | * Checks if columns has changed |
||
171 | * |
||
172 | * @param $rule |
||
173 | * @return boolean |
||
174 | */ |
||
175 | public static function hasChanged($rule): bool |
||
179 | |||
180 | /** |
||
181 | * Checks if columns needs to be constructed as a foreign key |
||
182 | * |
||
183 | * @param $rule |
||
184 | * @return boolean |
||
185 | */ |
||
186 | public static function isForeign($rule): bool |
||
190 | |||
191 | /** |
||
192 | * For aesthetic reasons |
||
193 | * |
||
194 | * @param $rule |
||
195 | * @param $needle |
||
196 | * @return bool |
||
197 | */ |
||
198 | private static function contains($rule, $needle): bool |
||
202 | } |
||
203 | |||
204 |