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 $unique |
97
|
|
|
*/ |
98
|
|
|
protected $unique=array(); |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var $table |
|
|
|
|
102
|
|
|
*/ |
103
|
|
|
protected $table; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return mixed|void |
107
|
|
|
*/ |
108
|
|
|
public function auto_increment() |
109
|
|
|
{ |
110
|
|
|
if(count($this->auto_increment)==0){ |
111
|
|
|
|
112
|
|
|
if($this->getLastName()===false){ |
113
|
|
|
$this->name[]='id'; |
114
|
|
|
$this->setTypes('int',14); |
115
|
|
|
} |
116
|
|
|
$this->auto_increment[$this->getLastName()]=true; |
117
|
|
|
$this->primaryKey(); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param $value |
123
|
|
|
* @return $this |
124
|
|
|
*/ |
125
|
|
|
public function comment($value) |
126
|
|
|
{ |
127
|
|
|
$this->comment[$this->getLastName()]=$value; |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param $name |
134
|
|
|
* @return Types |
135
|
|
|
*/ |
136
|
|
|
public function name($name) |
137
|
|
|
{ |
138
|
|
|
if(in_array($name,$this->name)){ |
139
|
|
|
$this->setError('You have written the '.$name.' name more than 1.'); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
$this->name[] = $name; |
143
|
|
|
|
144
|
|
|
return new Types($this); |
145
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param $value |
150
|
|
|
* @return $this|mixed |
151
|
|
|
*/ |
152
|
|
|
public function default($value) |
153
|
|
|
{ |
154
|
|
|
$this->default[$this->getLastName()]=$value; |
155
|
|
|
|
156
|
|
|
return $this; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param $value |
161
|
|
|
* @param bool $table |
162
|
|
|
* @return $this |
163
|
|
|
*/ |
164
|
|
|
public function collation($value,$table=false) |
165
|
|
|
{ |
166
|
|
|
if($table===false) |
167
|
|
|
{ |
168
|
|
|
$this->collation[$this->getLastName()]=$value; |
169
|
|
|
} |
170
|
|
|
else{ |
171
|
|
|
$this->collation['table']=$value; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return $this; |
|
|
|
|
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param null $name |
|
|
|
|
179
|
|
|
* @param null $value |
|
|
|
|
180
|
|
|
* @param bool $key |
181
|
|
|
* @return $this|WizardContract |
182
|
|
|
*/ |
183
|
|
|
public function index($name=null,$value=null,$key=false) |
184
|
|
|
{ |
185
|
|
|
$name = ($name===null) ? $this->getLastName() : $name; |
|
|
|
|
186
|
|
|
$value = ($value===null) ? $name : $value; |
|
|
|
|
187
|
|
|
|
188
|
|
|
if($key===false){ |
189
|
|
|
$this->index[$this->getLastName()]=['name'=>$name,'value'=>$value]; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if($key===true){ |
193
|
|
|
$this->index['indexes'][]=['name'=>$name,'value'=>$value]; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param $index_name |
201
|
|
|
* @param array $indexes |
202
|
|
|
* @return void |
203
|
|
|
*/ |
204
|
|
|
public function indexes($index_name,$indexes=array()) |
205
|
|
|
{ |
206
|
|
|
$this->index[$index_name] = $indexes; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param bool $null |
211
|
|
|
* @return $this |
212
|
|
|
*/ |
213
|
|
|
public function nullable($null=true) |
214
|
|
|
{ |
215
|
|
|
$this->nullable[$this->getLastName()]=$null; |
216
|
|
|
|
217
|
|
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* @return $this|WizardContract |
222
|
|
|
*/ |
223
|
|
|
public function primaryKey() |
224
|
|
|
{ |
225
|
|
|
$this->primaryKey[$this->getLastName()]=true; |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return TablePropertiesContract |
232
|
|
|
*/ |
233
|
|
|
public function table() |
234
|
|
|
{ |
235
|
|
|
return new TableProperties($this); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param $name |
240
|
|
|
* @param null $value |
|
|
|
|
241
|
|
|
* @return $this|mixed |
242
|
|
|
*/ |
243
|
|
|
public function unique($name=null,$value=null) |
244
|
|
|
{ |
245
|
|
|
$name = ($name===null) ? $this->getLastName() : $name; |
246
|
|
|
$value = ($value===null) ? $name : $value; |
|
|
|
|
247
|
|
|
|
248
|
|
|
$this->unique[$this->getLastName()] = ['name'=>$name,'value'=>$value]; |
249
|
|
|
|
250
|
|
|
return $this; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @param $name |
255
|
|
|
* @param null $value |
|
|
|
|
256
|
|
|
* @return $this|mixed |
257
|
|
|
*/ |
258
|
|
|
public function uniques($unique_name,$uniques=array()) |
259
|
|
|
{ |
260
|
|
|
$this->unique[$unique_name] = $uniques; |
261
|
|
|
} |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
|