1 | <?php |
||
9 | class SchemaParser implements Arrayable |
||
10 | { |
||
11 | /** |
||
12 | * The array of custom attributes. |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $customAttributes = [ |
||
17 | 'remember_token' => 'rememberToken()', |
||
18 | 'soft_delete' => 'softDeletes()', |
||
19 | ]; |
||
20 | |||
21 | /** |
||
22 | * The migration schema. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $schema; |
||
27 | |||
28 | /** |
||
29 | * The relationship keys. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $relationshipKeys = [ |
||
34 | 'belongsTo', |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * Create new instance. |
||
39 | * |
||
40 | * @param string|null $schema |
||
41 | */ |
||
42 | 13 | public function __construct($schema = null) |
|
46 | |||
47 | /** |
||
48 | * Parse a string to array of formatted schema. |
||
49 | * |
||
50 | * @param string $schema |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | 13 | public function parse($schema) |
|
70 | |||
71 | /** |
||
72 | * Get array of schema. |
||
73 | * |
||
74 | * @return array |
||
75 | */ |
||
76 | 13 | public function getSchemas() |
|
84 | |||
85 | /** |
||
86 | * Convert string migration to array. |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | 13 | public function toArray() |
|
94 | |||
95 | /** |
||
96 | * Render the migration to formatted script. |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | 12 | public function render() |
|
110 | |||
111 | /** |
||
112 | * Render up migration fields. |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 3 | public function up() |
|
120 | |||
121 | /** |
||
122 | * Render down migration fields. |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | 3 | public function down() |
|
137 | |||
138 | /** |
||
139 | * Create field. |
||
140 | * |
||
141 | * @param string $column |
||
142 | * @param array $attributes |
||
143 | * @param string $type |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | 4 | public function createField($column, $attributes, $type = 'add') |
|
161 | |||
162 | /** |
||
163 | * Add relation column. |
||
164 | * |
||
165 | * @param int $key |
||
166 | * @param string $field |
||
167 | * @param string $column |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | 1 | protected function addRelationColumn($key, $field, $column) |
|
189 | |||
190 | /** |
||
191 | * Format field to script. |
||
192 | * |
||
193 | * @param int $key |
||
194 | * @param string $field |
||
195 | * @param string $column |
||
196 | * |
||
197 | * @return string |
||
198 | */ |
||
199 | 2 | protected function addColumn($key, $field, $column) |
|
215 | |||
216 | /** |
||
217 | * Format field to script. |
||
218 | * |
||
219 | * @param int $key |
||
220 | * @param string $field |
||
221 | * @param string $column |
||
222 | * |
||
223 | * @return string |
||
224 | */ |
||
225 | 1 | protected function removeColumn($key, $field, $column) |
|
233 | |||
234 | /** |
||
235 | * Get column name from schema. |
||
236 | * |
||
237 | * @param string $schema |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | 4 | public function getColumn($schema) |
|
245 | |||
246 | /** |
||
247 | * Get column attributes. |
||
248 | * |
||
249 | * @param string $column |
||
250 | * @param string $schema |
||
251 | * |
||
252 | * @return array |
||
253 | */ |
||
254 | 4 | public function getAttributes($column, $schema) |
|
260 | |||
261 | /** |
||
262 | * Determine whether the given column is exist in customAttributes array. |
||
263 | * |
||
264 | * @param string $column |
||
265 | * |
||
266 | * @return bool |
||
267 | */ |
||
268 | 4 | public function hasCustomAttribute($column) |
|
272 | |||
273 | /** |
||
274 | * Get custom attributes value. |
||
275 | * |
||
276 | * @param string $column |
||
277 | * |
||
278 | * @return array |
||
279 | */ |
||
280 | public function getCustomAttribute($column) |
||
284 | } |
||
285 |