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