11<?php
22
3- namespace Webfactor \Laravel \Generators \Schemas ;
3+ namespace Webfactor \Laravel \Generators \Contracts ;
44
5- class MigrationField
5+ abstract class MigrationFieldAbstract implements FieldTypeInterface
66{
77 private $ name ;
88
9- private $ type ;
10-
119 private $ nullable = false ;
1210
1311 private $ unique = false ;
@@ -16,20 +14,12 @@ class MigrationField
1614
1715 private $ foreign = null ;
1816
19- public function __construct (string $ field )
17+ public function __construct (string $ name , array $ options = [] )
2018 {
21- $ this ->parse ($ field );
22- }
23-
24- private function parse (string $ field )
25- {
26- $ params = collect (explode (': ' , $ field ));
27-
28- $ this ->name = $ params ->pull (0 );
29- $ this ->type = $ params ->pull (1 );
19+ $ this ->name = $ name ;
3020
31- foreach ($ params as $ param ) {
32- $ this ->fillObject ($ param );
21+ foreach ($ options as $ option ) {
22+ $ this ->fillObject ($ option );
3323 }
3424 }
3525
@@ -94,43 +84,9 @@ public function isUnique(): bool
9484 return $ this ->unique ;
9585 }
9686
97- public function makeValidationRule (): string
98- {
99- $ rule = 'required ' ;
100-
101- switch ($ this ->getType ()) {
87+ abstract public function getRule (): string ;
10288
103- case 'string ' :
104- $ rule .= '|between:3,255 ' ;
105- break ;
89+ abstract public function getColumn (): array ;
10690
107- case 'integer ' :
108- $ rule .= '|integer ' ;
109- break ;
110-
111- case 'date ' :
112- $ rule .= '|date ' ;
113- break ;
114- }
115-
116- return $ rule ;
117- }
118-
119- public function makeColumn ()
120- {
121- return [
122- 'name ' => 'title ' ,
123- 'type ' => 'text ' ,
124- 'label ' => 'Title ' ,
125- ];
126- }
127-
128- public function makeField ()
129- {
130- return [
131- 'name ' => 'title ' ,
132- 'type ' => 'text ' ,
133- 'label ' => 'Title ' ,
134- ];
135- }
91+ abstract public function getField (): array ;
13692}
0 commit comments