1 | <?php |
||
7 | class RuleParser |
||
8 | { |
||
9 | /** |
||
10 | * @param $rule |
||
11 | * @return string|null |
||
12 | */ |
||
13 | public static function parseRule($rule = null) |
||
40 | |||
41 | /** |
||
42 | * @param string $rawRules |
||
43 | * @return string |
||
44 | */ |
||
45 | public static function toRule(string $rawRules): string |
||
78 | /** |
||
79 | * Parse the rules to column creation methods |
||
80 | * |
||
81 | * @param $fields |
||
82 | * @return string |
||
83 | */ |
||
84 | public static function fieldsToMigrationMethods(array $fields): string |
||
109 | |||
110 | /** |
||
111 | * @param $rule |
||
112 | * @return string |
||
113 | */ |
||
114 | public static function getAdditionalUpMethods($rule): string |
||
124 | |||
125 | /** |
||
126 | * Check if $rule should be handled as single method |
||
127 | * |
||
128 | * @param $rule |
||
129 | * @return mixed|string |
||
130 | */ |
||
131 | public static function isMethodOnly($rule) |
||
140 | |||
141 | /** |
||
142 | * Check if $rule contains any of the possible methods |
||
143 | * |
||
144 | * @param $rule |
||
145 | * @return mixed|string |
||
146 | */ |
||
147 | public static function getMethod($rule) |
||
157 | |||
158 | /** |
||
159 | * Parses the max:* rule |
||
160 | * |
||
161 | * @param $rule |
||
162 | * @return string |
||
163 | */ |
||
164 | public static function getMax($rule): string |
||
174 | |||
175 | /** |
||
176 | * Gets old name for renaming column |
||
177 | * |
||
178 | * @param $rule |
||
179 | * @return string |
||
180 | */ |
||
181 | public static function getRenameFrom($rule): string |
||
195 | |||
196 | /** |
||
197 | * Checks if column can be set to nullable |
||
198 | * |
||
199 | * @param $rule |
||
200 | * @return boolean |
||
201 | */ |
||
202 | public static function isRequired($rule): bool |
||
208 | |||
209 | /** |
||
210 | * Checks if columns needs to be set to unique |
||
211 | * |
||
212 | * @param $rule |
||
213 | * @return boolean |
||
214 | */ |
||
215 | public static function isIncrements($rule): bool |
||
225 | |||
226 | /** |
||
227 | * Checks if columns needs to be set to unique |
||
228 | * |
||
229 | * @param $rule |
||
230 | * @return boolean |
||
231 | */ |
||
232 | public static function isUnique($rule): bool |
||
236 | |||
237 | /** |
||
238 | * Checks if columns is unsigned |
||
239 | * |
||
240 | * @param $rule |
||
241 | * @return boolean |
||
242 | */ |
||
243 | public static function isUnsigned($rule): bool |
||
248 | |||
249 | |||
250 | /** |
||
251 | * Checks if columns has changed |
||
252 | * |
||
253 | * @param $rule |
||
254 | * @return boolean |
||
255 | */ |
||
256 | public static function hasChanged($rule): bool |
||
260 | |||
261 | /** |
||
262 | * Checks if columns needs to be constructed as a foreign key |
||
263 | * |
||
264 | * @param $rule |
||
265 | * @return boolean |
||
266 | */ |
||
267 | public static function isForeign($rule): bool |
||
271 | |||
272 | /** |
||
273 | * For aesthetic reasons |
||
274 | * |
||
275 | * @param $rule |
||
276 | * @param $needles |
||
277 | * @return bool |
||
278 | */ |
||
279 | private static function ruleContains($rule, array $needles): bool |
||
287 | } |
||
288 | |||
289 |