1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Migratio\GrammarStructure\Mysql\Wizard; |
4
|
|
|
|
5
|
|
|
use Migratio\Contract\TablePropertiesContract; |
6
|
|
|
use Migratio\Contract\WizardContract; |
7
|
|
|
|
8
|
|
|
class Wizard extends WizardHelper implements WizardContract |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var $randomInstance |
|
|
|
|
12
|
|
|
*/ |
13
|
|
|
public static $randomInstance; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array $error |
17
|
|
|
*/ |
18
|
|
|
protected $error = array(); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
protected $alterType = []; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $auto_increment=array(); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var $collation |
|
|
|
|
32
|
|
|
*/ |
33
|
|
|
protected $collation; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var $comment |
|
|
|
|
37
|
|
|
*/ |
38
|
|
|
protected $comment; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array $primaryKey |
42
|
|
|
*/ |
43
|
|
|
protected $primaryKey=array(); |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var array $references |
47
|
|
|
*/ |
48
|
|
|
protected $references=array(); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var $schemaType |
|
|
|
|
52
|
|
|
*/ |
53
|
|
|
protected $schemaType; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var $file |
|
|
|
|
57
|
|
|
*/ |
58
|
|
|
protected $file; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var $name array |
|
|
|
|
62
|
|
|
*/ |
63
|
|
|
protected $name=array(); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var array $nullable |
67
|
|
|
*/ |
68
|
|
|
protected $nullable=array(); |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var array $types |
72
|
|
|
*/ |
73
|
|
|
protected $types=array(); |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var $engine |
|
|
|
|
77
|
|
|
*/ |
78
|
|
|
protected $engine; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var $default array |
|
|
|
|
82
|
|
|
*/ |
83
|
|
|
protected $default=array(); |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var array $index |
87
|
|
|
*/ |
88
|
|
|
protected $index=array(); |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var array $unique |
92
|
|
|
*/ |
93
|
|
|
protected $unique=array(); |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var $table |
|
|
|
|
97
|
|
|
*/ |
98
|
|
|
protected $table; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return mixed|void |
102
|
|
|
*/ |
103
|
|
|
public function auto_increment() |
104
|
|
|
{ |
105
|
|
|
if(count($this->auto_increment)==0){ |
106
|
|
|
|
107
|
|
|
if($this->getLastName()===false){ |
108
|
|
|
$this->name[]='id'; |
109
|
|
|
$this->setTypes('int',14); |
110
|
|
|
} |
111
|
|
|
$this->auto_increment[$this->getLastName()]=true; |
112
|
|
|
$this->primaryKey(); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param $value |
118
|
|
|
* @return $this |
119
|
|
|
*/ |
120
|
|
|
public function comment($value) |
121
|
|
|
{ |
122
|
|
|
$this->comment[$this->getLastName()]=$value; |
123
|
|
|
|
124
|
|
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param $name |
129
|
|
|
* @return Types |
130
|
|
|
*/ |
131
|
|
|
public function name($name) |
132
|
|
|
{ |
133
|
|
|
if(in_array($name,$this->name)){ |
134
|
|
|
$this->setError('You have written the '.$name.' name more than 1.'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$this->name[]=$name; |
138
|
|
|
|
139
|
|
|
return new Types($this); |
140
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param $value |
145
|
|
|
* @return $this|mixed |
146
|
|
|
*/ |
147
|
|
|
public function default($value) |
148
|
|
|
{ |
149
|
|
|
$this->default[$this->getLastName()]=$value; |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param $value |
156
|
|
|
* @param bool $table |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
|
|
public function collation($value,$table=false) |
160
|
|
|
{ |
161
|
|
|
if($table===false) |
162
|
|
|
{ |
163
|
|
|
$this->collation[$this->getLastName()]=$value; |
164
|
|
|
} |
165
|
|
|
else{ |
166
|
|
|
$this->collation['table']=$value; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $this; |
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param null $name |
|
|
|
|
174
|
|
|
* @param null $value |
|
|
|
|
175
|
|
|
* @param bool $key |
176
|
|
|
* @return $this|WizardContract |
177
|
|
|
*/ |
178
|
|
|
public function index($name=null,$value=null,$key=false) |
179
|
|
|
{ |
180
|
|
|
$name = ($name===null) ? $this->getLastName() : $name; |
|
|
|
|
181
|
|
|
$value = ($value===null) ? $name : $value; |
|
|
|
|
182
|
|
|
|
183
|
|
|
if($key===false){ |
184
|
|
|
$this->index[$this->getLastName()]=['name'=>$name,'value'=>$value]; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
if($key===true){ |
188
|
|
|
$this->index['indexes'][]=['name'=>$name,'value'=>$value]; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param bool $null |
196
|
|
|
* @return $this |
197
|
|
|
*/ |
198
|
|
|
public function nullable($null=true) |
199
|
|
|
{ |
200
|
|
|
$this->nullable[$this->getLastName()]=$null; |
201
|
|
|
|
202
|
|
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @return $this|WizardContract |
207
|
|
|
*/ |
208
|
|
|
public function primaryKey() |
209
|
|
|
{ |
210
|
|
|
$this->primaryKey[$this->getLastName()]=true; |
211
|
|
|
|
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return TablePropertiesContract |
217
|
|
|
*/ |
218
|
|
|
public function table() |
219
|
|
|
{ |
220
|
|
|
return new TableProperties($this); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @param $name |
225
|
|
|
* @param null $value |
|
|
|
|
226
|
|
|
* @return $this|mixed |
227
|
|
|
*/ |
228
|
|
|
public function unique($name=null,$value=null) |
229
|
|
|
{ |
230
|
|
|
$name = ($name===null) ? $this->getLastName() : $name; |
231
|
|
|
$value = ($value===null) ? $name : $value; |
|
|
|
|
232
|
|
|
|
233
|
|
|
$this->unique[$this->getLastName()]=['name'=>$name,'value'=>$value]; |
234
|
|
|
|
235
|
|
|
return $this; |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|