@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @var $type |
17 | 17 | */ |
18 | - public $type='model'; |
|
18 | + public $type = 'model'; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var array |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * @var $commandRule |
34 | 34 | */ |
35 | - public $commandRule=['model','?table']; |
|
35 | + public $commandRule = ['model', '?table']; |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @method create |
39 | 39 | * @return mixed |
40 | 40 | */ |
41 | - public function create(){ |
|
41 | + public function create() { |
|
42 | 42 | |
43 | 43 | $this->argument['file'] = $this->argument['model']; |
44 | 44 | |
45 | - if(!isset($this->argument['table'])){ |
|
45 | + if (!isset($this->argument['table'])) { |
|
46 | 46 | $this->argument['table'] = $this->argument['file'].'s'; |
47 | 47 | } |
48 | 48 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $this->touch['model/builder'] = $this->directory['builderDir'].''.DIRECTORY_SEPARATOR.''.$this->argument['file'].'Builder.php'; |
67 | 67 | $this->touch['model/contract'] = $this->directory['contract'].''.DIRECTORY_SEPARATOR.''.$this->argument['file'].'Contract.php'; |
68 | 68 | |
69 | - if(!file_exists($this->directory['helper'].''.DIRECTORY_SEPARATOR.'Scope.php')){ |
|
69 | + if (!file_exists($this->directory['helper'].''.DIRECTORY_SEPARATOR.'Scope.php')) { |
|
70 | 70 | $this->touch['model/scope'] = $this->directory['helper'].''.DIRECTORY_SEPARATOR.'Scope.php'; |
71 | 71 | } |
72 | 72 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | |
75 | 75 | $entityDir = $this->directory['modelDir'].''.DIRECTORY_SEPARATOR.'Entity'; |
76 | 76 | |
77 | - if(!file_exists($entityDir)){ |
|
77 | + if (!file_exists($entityDir)) { |
|
78 | 78 | files()->makeDirectory($entityDir); |
79 | 79 | } |
80 | 80 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | $entityClass = $entityDir.''.DIRECTORY_SEPARATOR.''.$entityTableName.''.DIRECTORY_SEPARATOR.''.$entityTableName; |
84 | 84 | |
85 | 85 | |
86 | - $generator = new Generator($entityDir,'EntityMap'); |
|
86 | + $generator = new Generator($entityDir, 'EntityMap'); |
|
87 | 87 | |
88 | - if(!file_exists($entityDir.''.DIRECTORY_SEPARATOR.'EntityMap.php')){ |
|
88 | + if (!file_exists($entityDir.''.DIRECTORY_SEPARATOR.'EntityMap.php')) { |
|
89 | 89 | |
90 | 90 | //$this->setAnnotations(); |
91 | 91 | $generator->createClass(); |
@@ -119,15 +119,15 @@ discard block |
||
119 | 119 | |
120 | 120 | |
121 | 121 | //set builder map |
122 | - $generator = new Generator($this->directory['builderDir'],'BuilderMap'); |
|
122 | + $generator = new Generator($this->directory['builderDir'], 'BuilderMap'); |
|
123 | 123 | |
124 | - if(!file_exists($this->directory['builderDir'].''.DIRECTORY_SEPARATOR.'BuilderMap.php')){ |
|
124 | + if (!file_exists($this->directory['builderDir'].''.DIRECTORY_SEPARATOR.'BuilderMap.php')) { |
|
125 | 125 | |
126 | 126 | $this->setAnnotations(); |
127 | 127 | $generator->createClass(); |
128 | 128 | } |
129 | 129 | |
130 | - if(!file_exists($this->touch['model/model'])){ |
|
130 | + if (!file_exists($this->touch['model/model'])) { |
|
131 | 131 | |
132 | 132 | $generator->createMethod([ |
133 | 133 | strtolower($this->argument['file']) |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | } |
149 | 149 | |
150 | 150 | //set project touch |
151 | - $this->file->touch($this,[ |
|
151 | + $this->file->touch($this, [ |
|
152 | 152 | 'stub'=>'Model_Create' |
153 | 153 | ]); |
154 | 154 | |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | /** |
160 | 160 | * @return bool |
161 | 161 | */ |
162 | - private function setAnnotations(){ |
|
162 | + private function setAnnotations() { |
|
163 | 163 | |
164 | 164 | $entityMap = app()->path()->model().''.DIRECTORY_SEPARATOR.'Entity'.DIRECTORY_SEPARATOR.'EntityMap.php'; |
165 | 165 | |
166 | - if(file_exists($entityMap)){ |
|
166 | + if (file_exists($entityMap)) { |
|
167 | 167 | |
168 | 168 | Utils::changeClass(path()->serviceAnnotations().'.php', |
169 | 169 | [ |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function get() |
16 | 16 | { |
17 | - if(!isset($this->config['paths'][0])){ |
|
17 | + if (!isset($this->config['paths'][0])) { |
|
18 | 18 | exit(); |
19 | 19 | } |
20 | 20 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | |
28 | 28 | $list = []; |
29 | 29 | |
30 | - foreach ($migrations as $table=>$item){ |
|
30 | + foreach ($migrations as $table=>$item) { |
|
31 | 31 | $list[] = strtolower($table); |
32 | 32 | } |
33 | 33 | |
34 | - if(isset($arguments['only'])){ |
|
34 | + if (isset($arguments['only'])) { |
|
35 | 35 | $dbtables = $this->getOnly($dbtables); |
36 | 36 | } |
37 | 37 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | echo 'Toplam : '.count($dbtables).' Table'; |
41 | 41 | echo PHP_EOL; |
42 | 42 | |
43 | - foreach ($dbtables as $dbtablekey=>$dbtable){ |
|
43 | + foreach ($dbtables as $dbtablekey=>$dbtable) { |
|
44 | 44 | |
45 | 45 | $dbtablekey = $dbtablekey+1; |
46 | 46 | |
@@ -49,45 +49,45 @@ discard block |
||
49 | 49 | $dbtable = ucfirst($dbtable); |
50 | 50 | $makeDirectory = $directory.''.DIRECTORY_SEPARATOR.''.$dbtable; |
51 | 51 | |
52 | - if(!file_exists($makeDirectory)){ |
|
53 | - files()->makeDirectory($makeDirectory,0755,true); |
|
54 | - $exist=false; |
|
52 | + if (!file_exists($makeDirectory)) { |
|
53 | + files()->makeDirectory($makeDirectory, 0755, true); |
|
54 | + $exist = false; |
|
55 | 55 | } |
56 | - else{ |
|
57 | - $exist=true; |
|
56 | + else { |
|
57 | + $exist = true; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $migrationName = time().'_'.$dbtable.''; |
61 | 61 | |
62 | - if($exist===false){ |
|
62 | + if ($exist===false) { |
|
63 | 63 | |
64 | - $content = $this->getContentFile($this->getStubPath().''.DIRECTORY_SEPARATOR.'pullCreate.stub',[ |
|
64 | + $content = $this->getContentFile($this->getStubPath().''.DIRECTORY_SEPARATOR.'pullCreate.stub', [ |
|
65 | 65 | 'className' => $dbtable, |
66 | 66 | 'informations' => $informations |
67 | 67 | ]); |
68 | 68 | |
69 | - $contentResult = files()->put($makeDirectory.''.DIRECTORY_SEPARATOR.''.$migrationName.'.php',$content); |
|
69 | + $contentResult = files()->put($makeDirectory.''.DIRECTORY_SEPARATOR.''.$migrationName.'.php', $content); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | |
73 | 73 | |
74 | - if(isset($contentResult) && $contentResult!==false){ |
|
74 | + if (isset($contentResult) && $contentResult!==false) { |
|
75 | 75 | |
76 | 76 | $this->schema->getConnection()->generateEntity($dbtable); |
77 | 77 | |
78 | - if(substr($dbtable,-1)=='s'){ |
|
79 | - app()->command('model create','model:'.strtolower(substr($dbtable,0,-1)).' table:'.$dbtable.' entity:'.$dbtable); |
|
78 | + if (substr($dbtable, -1)=='s') { |
|
79 | + app()->command('model create', 'model:'.strtolower(substr($dbtable, 0, -1)).' table:'.$dbtable.' entity:'.$dbtable); |
|
80 | 80 | } |
81 | - else{ |
|
82 | - app()->command('model create','model:'.strtolower($dbtable).' table:'.$dbtable.' entity:'.$dbtable); |
|
81 | + else { |
|
82 | + app()->command('model create', 'model:'.strtolower($dbtable).' table:'.$dbtable.' entity:'.$dbtable); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | echo $dbtablekey.'- '.$migrationName.' ---> Ok'; |
86 | 86 | } |
87 | - elseif($exist){ |
|
87 | + elseif ($exist) { |
|
88 | 88 | echo $dbtablekey.'- '.$migrationName.' ---> (Already Exist)'; |
89 | 89 | } |
90 | - else{ |
|
90 | + else { |
|
91 | 91 | echo $dbtablekey.'- '.$migrationName.' ---> Fail'; |
92 | 92 | } |
93 | 93 | |
@@ -115,46 +115,46 @@ discard block |
||
115 | 115 | |
116 | 116 | $list = []; |
117 | 117 | |
118 | - foreach ($columns as $key=>$data){ |
|
118 | + foreach ($columns as $key=>$data) { |
|
119 | 119 | |
120 | - $data['Type'] = rtrim(str_replace('unsigned','',$data['Type'])); |
|
120 | + $data['Type'] = rtrim(str_replace('unsigned', '', $data['Type'])); |
|
121 | 121 | |
122 | 122 | $field = $data['Field']; |
123 | 123 | $list[] = '$wizard->name(\''.$field.'\')'; |
124 | 124 | $list[] = '->'.$this->getColumnTransformers($data['Type']).''; |
125 | 125 | |
126 | 126 | //default block |
127 | - if(!is_null($data['Default'])){ |
|
127 | + if (!is_null($data['Default'])) { |
|
128 | 128 | $default = $data['Default']; |
129 | - $list[] = '->default(\''.$default.'\')'; |
|
129 | + $list[] = '->default(\''.$default.'\')'; |
|
130 | 130 | } |
131 | 131 | |
132 | - $getIndex = $this->getIndexInformation($indexes,$data['Field']); |
|
132 | + $getIndex = $this->getIndexInformation($indexes, $data['Field']); |
|
133 | 133 | |
134 | 134 | //unique block |
135 | - if($getIndex['Non_unique']=='0' && $getIndex['Key_name']!=='PRIMARY'){ |
|
135 | + if ($getIndex['Non_unique']=='0' && $getIndex['Key_name']!=='PRIMARY') { |
|
136 | 136 | $indexName = $getIndex['Key_name']; |
137 | - $list[] = '->unique(\''.$indexName.'\')'; |
|
137 | + $list[] = '->unique(\''.$indexName.'\')'; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | //index block |
141 | - if($getIndex['Non_unique']=='1' && $getIndex['Key_name']!=='PRIMARY'){ |
|
141 | + if ($getIndex['Non_unique']=='1' && $getIndex['Key_name']!=='PRIMARY') { |
|
142 | 142 | $columnName = $getIndex['Column_name']; |
143 | 143 | $indexName = $getIndex['Key_name']; |
144 | 144 | |
145 | - if(count($multipleIndexes[$indexName])==1){ |
|
145 | + if (count($multipleIndexes[$indexName])==1) { |
|
146 | 146 | $list[] = '->index(\''.$indexName.'\')'; |
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | 150 | //comment block |
151 | - if(strlen($data['Comment'])>0){ |
|
151 | + if (strlen($data['Comment'])>0) { |
|
152 | 152 | $comment = $data['Comment']; |
153 | 153 | $list[] = '->comment(\''.$comment.'\')'; |
154 | 154 | } |
155 | 155 | |
156 | 156 | //auto increment block |
157 | - if($data['Extra']=='auto_increment'){ |
|
157 | + if ($data['Extra']=='auto_increment') { |
|
158 | 158 | $list[] = '->auto_increment()'; |
159 | 159 | } |
160 | 160 | |
@@ -169,39 +169,39 @@ discard block |
||
169 | 169 | |
170 | 170 | //table indexes |
171 | 171 | foreach ($multipleIndexes as $indexName=>$values) { |
172 | - if(count($values)>1){ |
|
173 | - $values = '\''.implode('\',\'',$values).'\''; |
|
172 | + if (count($values)>1) { |
|
173 | + $values = '\''.implode('\',\'', $values).'\''; |
|
174 | 174 | $list[] = ' $wizard->table()->indexes(\''.$indexName.'\',['.$values.']); |
175 | 175 | '; |
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
179 | - if(count($foreignKeys)){ |
|
179 | + if (count($foreignKeys)) { |
|
180 | 180 | |
181 | 181 | $constraintName = $foreignKeys['CONSTRAINT_NAME']; |
182 | 182 | $key = $foreignKeys['COLUMN_NAME']; |
183 | 183 | $referenceTable = $foreignKeys['REFERENCED_TABLE_NAME']; |
184 | 184 | $referenceColumn = $foreignKeys['REFERENCED_COLUMN_NAME']; |
185 | 185 | |
186 | - if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
|
186 | + if ($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT') { |
|
187 | 187 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\'); |
188 | 188 | '; |
189 | 189 | } |
190 | 190 | |
191 | - if($foreignKeys['UPDATE_RULE']!=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
|
191 | + if ($foreignKeys['UPDATE_RULE']!=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT') { |
|
192 | 192 | $rule = $foreignKeys['UPDATE_RULE']; |
193 | 193 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onUpdate()->'.strtolower($rule).'(); |
194 | 194 | '; |
195 | 195 | } |
196 | 196 | |
197 | - if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']!=='RESTRICT'){ |
|
197 | + if ($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']!=='RESTRICT') { |
|
198 | 198 | $rule = $foreignKeys['DELETE_RULE']; |
199 | 199 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onDelete()->'.strtolower($rule).'(); |
200 | 200 | '; |
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - return implode('',$list); |
|
204 | + return implode('', $list); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -212,43 +212,43 @@ discard block |
||
212 | 212 | */ |
213 | 213 | private function getColumnTransformers($column) |
214 | 214 | { |
215 | - if($column=='datetime'){ |
|
215 | + if ($column=='datetime') { |
|
216 | 216 | return 'datetime()'; |
217 | 217 | } |
218 | - elseif($column=='longtext'){ |
|
218 | + elseif ($column=='longtext') { |
|
219 | 219 | return 'longtext()'; |
220 | 220 | } |
221 | - elseif($column=='date'){ |
|
221 | + elseif ($column=='date') { |
|
222 | 222 | return 'date()'; |
223 | 223 | } |
224 | - elseif($column=='text'){ |
|
224 | + elseif ($column=='text') { |
|
225 | 225 | return 'text()'; |
226 | 226 | } |
227 | - elseif($column=='timestamp'){ |
|
227 | + elseif ($column=='timestamp') { |
|
228 | 228 | return 'timestamp()'; |
229 | 229 | } |
230 | - elseif($column=='mediumint'){ |
|
230 | + elseif ($column=='mediumint') { |
|
231 | 231 | return 'mediumint()'; |
232 | 232 | } |
233 | - elseif($column=='tinyint'){ |
|
233 | + elseif ($column=='tinyint') { |
|
234 | 234 | return 'tinyint()'; |
235 | 235 | } |
236 | - elseif($column=='float'){ |
|
236 | + elseif ($column=='float') { |
|
237 | 237 | return 'float()'; |
238 | 238 | } |
239 | - elseif($column=='mediumtext'){ |
|
239 | + elseif ($column=='mediumtext') { |
|
240 | 240 | return 'mediumtext()'; |
241 | 241 | } |
242 | - elseif($column=='mediumblob'){ |
|
242 | + elseif ($column=='mediumblob') { |
|
243 | 243 | return 'mediumblob()'; |
244 | 244 | } |
245 | - elseif($column=='blob'){ |
|
245 | + elseif ($column=='blob') { |
|
246 | 246 | return 'blob()'; |
247 | 247 | } |
248 | - elseif(preg_match('@enum.*\((.*?)\)@',$column,$enum)){ |
|
248 | + elseif (preg_match('@enum.*\((.*?)\)@', $column, $enum)) { |
|
249 | 249 | return 'enum(['.$enum[1].'])'; |
250 | 250 | } |
251 | - else{ |
|
251 | + else { |
|
252 | 252 | return $column; |
253 | 253 | } |
254 | 254 | } |
@@ -260,11 +260,11 @@ discard block |
||
260 | 260 | * @param $field |
261 | 261 | * @return void|mixed |
262 | 262 | */ |
263 | - private function getIndexInformation($index,$field) |
|
263 | + private function getIndexInformation($index, $field) |
|
264 | 264 | { |
265 | 265 | foreach ($index as $key=>$item) { |
266 | 266 | |
267 | - if($item['Column_name'] == $field){ |
|
267 | + if ($item['Column_name']==$field) { |
|
268 | 268 | return $index[$key]; |
269 | 269 | } |
270 | 270 | } |
@@ -282,13 +282,13 @@ discard block |
||
282 | 282 | { |
283 | 283 | $arguments = $this->schema->getArguments(); |
284 | 284 | |
285 | - $only = explode(',',$arguments['only']); |
|
285 | + $only = explode(',', $arguments['only']); |
|
286 | 286 | |
287 | 287 | $list = []; |
288 | 288 | |
289 | - foreach($only as $table){ |
|
289 | + foreach ($only as $table) { |
|
290 | 290 | |
291 | - if(in_array($table,$tables) || in_array($table = strtolower($table),$tables)){ |
|
291 | + if (in_array($table, $tables) || in_array($table = strtolower($table), $tables)) { |
|
292 | 292 | $list[] = $table; |
293 | 293 | } |
294 | 294 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | { |
308 | 308 | $list = []; |
309 | 309 | foreach ($index as $key=>$item) { |
310 | - if($item['Non_unique']==1 && $item['Key_name']!=='PRIMARY'){ |
|
310 | + if ($item['Non_unique']==1 && $item['Key_name']!=='PRIMARY') { |
|
311 | 311 | $list[$item['Key_name']][] = $item['Column_name']; |
312 | 312 | } |
313 | 313 | } |
@@ -52,8 +52,7 @@ discard block |
||
52 | 52 | if(!file_exists($makeDirectory)){ |
53 | 53 | files()->makeDirectory($makeDirectory,0755,true); |
54 | 54 | $exist=false; |
55 | - } |
|
56 | - else{ |
|
55 | + } else{ |
|
57 | 56 | $exist=true; |
58 | 57 | } |
59 | 58 | |
@@ -77,17 +76,14 @@ discard block |
||
77 | 76 | |
78 | 77 | if(substr($dbtable,-1)=='s'){ |
79 | 78 | app()->command('model create','model:'.strtolower(substr($dbtable,0,-1)).' table:'.$dbtable.' entity:'.$dbtable); |
80 | - } |
|
81 | - else{ |
|
79 | + } else{ |
|
82 | 80 | app()->command('model create','model:'.strtolower($dbtable).' table:'.$dbtable.' entity:'.$dbtable); |
83 | 81 | } |
84 | 82 | |
85 | 83 | echo $dbtablekey.'- '.$migrationName.' ---> Ok'; |
86 | - } |
|
87 | - elseif($exist){ |
|
84 | + } elseif($exist){ |
|
88 | 85 | echo $dbtablekey.'- '.$migrationName.' ---> (Already Exist)'; |
89 | - } |
|
90 | - else{ |
|
86 | + } else{ |
|
91 | 87 | echo $dbtablekey.'- '.$migrationName.' ---> Fail'; |
92 | 88 | } |
93 | 89 | |
@@ -214,41 +210,29 @@ discard block |
||
214 | 210 | { |
215 | 211 | if($column=='datetime'){ |
216 | 212 | return 'datetime()'; |
217 | - } |
|
218 | - elseif($column=='longtext'){ |
|
213 | + } elseif($column=='longtext'){ |
|
219 | 214 | return 'longtext()'; |
220 | - } |
|
221 | - elseif($column=='date'){ |
|
215 | + } elseif($column=='date'){ |
|
222 | 216 | return 'date()'; |
223 | - } |
|
224 | - elseif($column=='text'){ |
|
217 | + } elseif($column=='text'){ |
|
225 | 218 | return 'text()'; |
226 | - } |
|
227 | - elseif($column=='timestamp'){ |
|
219 | + } elseif($column=='timestamp'){ |
|
228 | 220 | return 'timestamp()'; |
229 | - } |
|
230 | - elseif($column=='mediumint'){ |
|
221 | + } elseif($column=='mediumint'){ |
|
231 | 222 | return 'mediumint()'; |
232 | - } |
|
233 | - elseif($column=='tinyint'){ |
|
223 | + } elseif($column=='tinyint'){ |
|
234 | 224 | return 'tinyint()'; |
235 | - } |
|
236 | - elseif($column=='float'){ |
|
225 | + } elseif($column=='float'){ |
|
237 | 226 | return 'float()'; |
238 | - } |
|
239 | - elseif($column=='mediumtext'){ |
|
227 | + } elseif($column=='mediumtext'){ |
|
240 | 228 | return 'mediumtext()'; |
241 | - } |
|
242 | - elseif($column=='mediumblob'){ |
|
229 | + } elseif($column=='mediumblob'){ |
|
243 | 230 | return 'mediumblob()'; |
244 | - } |
|
245 | - elseif($column=='blob'){ |
|
231 | + } elseif($column=='blob'){ |
|
246 | 232 | return 'blob()'; |
247 | - } |
|
248 | - elseif(preg_match('@enum.*\((.*?)\)@',$column,$enum)){ |
|
233 | + } elseif(preg_match('@enum.*\((.*?)\)@',$column,$enum)){ |
|
249 | 234 | return 'enum(['.$enum[1].'])'; |
250 | - } |
|
251 | - else{ |
|
235 | + } else{ |
|
252 | 236 | return $column; |
253 | 237 | } |
254 | 238 | } |
@@ -14,37 +14,37 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function processHandler() |
16 | 16 | { |
17 | - return $this->errorHandler(function(){ |
|
17 | + return $this->errorHandler(function() { |
|
18 | 18 | |
19 | 19 | $results = []; |
20 | 20 | |
21 | - foreach ($this->list as $table =>$datas){ |
|
21 | + foreach ($this->list as $table =>$datas) { |
|
22 | 22 | |
23 | - foreach ($datas as $data){ |
|
23 | + foreach ($datas as $data) { |
|
24 | 24 | |
25 | - $query = $this->queryBuilder($table,$data); |
|
25 | + $query = $this->queryBuilder($table, $data); |
|
26 | 26 | |
27 | 27 | $query = $query->handle(); |
28 | 28 | |
29 | 29 | |
30 | - if($query===false){ |
|
30 | + if ($query===false) { |
|
31 | 31 | $results[] = []; |
32 | 32 | } |
33 | - else{ |
|
34 | - $status =($query['result']!==false) ? true : false; |
|
33 | + else { |
|
34 | + $status = ($query['result']!==false) ? true : false; |
|
35 | 35 | |
36 | - if($status){ |
|
36 | + if ($status) { |
|
37 | 37 | $this->schema->getConnection()->generateEntity($table); |
38 | 38 | |
39 | - if(substr($table,-1)=='s'){ |
|
40 | - app()->command('model create','model:'.strtolower(substr($table,0,-1)).' table:'.$table.' entity:'.$table); |
|
39 | + if (substr($table, -1)=='s') { |
|
40 | + app()->command('model create', 'model:'.strtolower(substr($table, 0, -1)).' table:'.$table.' entity:'.$table); |
|
41 | 41 | } |
42 | - else{ |
|
43 | - app()->command('model create','model:'.strtolower($table).' table:'.$table.' entity:'.$table); |
|
42 | + else { |
|
43 | + app()->command('model create', 'model:'.strtolower($table).' table:'.$table.' entity:'.$table); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | - $results[]= [ |
|
47 | + $results[] = [ |
|
48 | 48 | 'success'=>$status, |
49 | 49 | 'file'=>$data->getFile(), |
50 | 50 | 'table'=>$table, |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | { |
75 | 75 | $alterBinds = $object->getAlterBinds(); |
76 | 76 | |
77 | - if(!is_null($alterBinds) && count($alterBinds)>1){ |
|
77 | + if (!is_null($alterBinds) && count($alterBinds)>1) { |
|
78 | 78 | exception()->runtime('Only one command can be applied to alter groups'); |
79 | 79 | } |
80 | 80 | |
81 | - if(count($object->getError())){ |
|
81 | + if (count($object->getError())) { |
|
82 | 82 | exception()->runtime(''.$object->getFile().' -> '.$object->getError()[0].''); |
83 | 83 | } |
84 | 84 |
@@ -29,8 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | if($query===false){ |
31 | 31 | $results[] = []; |
32 | - } |
|
33 | - else{ |
|
32 | + } else{ |
|
34 | 33 | $status =($query['result']!==false) ? true : false; |
35 | 34 | |
36 | 35 | if($status){ |
@@ -38,8 +37,7 @@ discard block |
||
38 | 37 | |
39 | 38 | if(substr($table,-1)=='s'){ |
40 | 39 | app()->command('model create','model:'.strtolower(substr($table,0,-1)).' table:'.$table.' entity:'.$table); |
41 | - } |
|
42 | - else{ |
|
40 | + } else{ |
|
43 | 41 | app()->command('model create','model:'.strtolower($table).' table:'.$table.' entity:'.$table); |
44 | 42 | } |
45 | 43 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | { |
51 | 51 | $collation = $this->connection()->query('SHOW COLLATION LIKE \''.$collation.'%\'')->fetchAll(); |
52 | 52 | |
53 | - if(isset($collation[0])){ |
|
53 | + if (isset($collation[0])) { |
|
54 | 54 | return $collation[0]['Charset']; |
55 | 55 | } |
56 | 56 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | { |
68 | 68 | $status = $this->connection()->query('show table status like \''.$table.'\'')->fetchAll(); |
69 | 69 | |
70 | - if(isset($status[0])){ |
|
70 | + if (isset($status[0])) { |
|
71 | 71 | return $status[0]; |
72 | 72 | } |
73 | 73 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | WHERE rc.CONSTRAINT_SCHEMA = \''.$database.'\' |
104 | 104 | AND rc.TABLE_NAME = \''.$table.'\' AND r.REFERENCED_TABLE_NAME is not null')->fetchAll(); |
105 | 105 | |
106 | - if(isset($query[0])){ |
|
106 | + if (isset($query[0])) { |
|
107 | 107 | return $query[0]; |
108 | 108 | } |
109 | 109 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | try { |
122 | 122 | |
123 | - $query =$this->connection()->query($query); |
|
123 | + $query = $this->connection()->query($query); |
|
124 | 124 | |
125 | 125 | return [ |
126 | 126 | 'result'=>true, |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | 'message'=>null, |
129 | 129 | ]; |
130 | 130 | } |
131 | - catch (\PDOException $exception){ |
|
131 | + catch (\PDOException $exception) { |
|
132 | 132 | |
133 | 133 | return [ |
134 | 134 | 'result'=>false, |
@@ -144,15 +144,15 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function generateEntity($table) |
146 | 146 | { |
147 | - if(in_array($table,$this->showTables()) || in_array($table = strtolower($table),$this->showTables())){ |
|
147 | + if (in_array($table, $this->showTables()) || in_array($table = strtolower($table), $this->showTables())) { |
|
148 | 148 | |
149 | 149 | $entityDirectory = path()->model().''.DIRECTORY_SEPARATOR.'Entity'; |
150 | 150 | |
151 | - if(!file_exists(app()->path()->model())){ |
|
151 | + if (!file_exists(app()->path()->model())) { |
|
152 | 152 | files()->makeDirectory(app()->path()->model()); |
153 | 153 | } |
154 | 154 | |
155 | - if(!file_exists($entityDirectory)){ |
|
155 | + if (!file_exists($entityDirectory)) { |
|
156 | 156 | files()->makeDirectory($entityDirectory); |
157 | 157 | } |
158 | 158 | |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | $list[] = $column['Field']; |
165 | 165 | } |
166 | 166 | |
167 | - if(!file_exists($entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table))){ |
|
168 | - $generator = new Generator($entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table),$table.''); |
|
167 | + if (!file_exists($entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table))) { |
|
168 | + $generator = new Generator($entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table), $table.''); |
|
169 | 169 | |
170 | 170 | $generator->createClass(); |
171 | 171 | } |
@@ -174,15 +174,15 @@ discard block |
||
174 | 174 | $abstractClassPath = $entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table).''.DIRECTORY_SEPARATOR.'Entity'; |
175 | 175 | $abstractNamespace = Utils::getNamespace($abstractClassPath.''.DIRECTORY_SEPARATOR.''.ucfirst($table).'Abstract'); |
176 | 176 | |
177 | - $generator->createClassExtend($abstractNamespace,ucfirst($table).'Abstract'); |
|
177 | + $generator->createClassExtend($abstractNamespace, ucfirst($table).'Abstract'); |
|
178 | 178 | |
179 | - $generator = new Generator($abstractClassPath,$table.'Abstract'); |
|
179 | + $generator = new Generator($abstractClassPath, $table.'Abstract'); |
|
180 | 180 | |
181 | 181 | $generator->createClass(); |
182 | 182 | |
183 | - $method =array_merge([ |
|
183 | + $method = array_merge([ |
|
184 | 184 | '__construct' |
185 | - ],array_merge($list,['__get'])); |
|
185 | + ], array_merge($list, ['__get'])); |
|
186 | 186 | |
187 | 187 | $generator->createMethod($method); |
188 | 188 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | |
208 | 208 | $generator->createClassDocument($createClassDocument); |
209 | 209 | |
210 | - $generator->createMethodDocument(array_merge($createMethodDocument,[ |
|
210 | + $generator->createMethodDocument(array_merge($createMethodDocument, [ |
|
211 | 211 | '__construct' => [ |
212 | 212 | ''.$table.' constructor.', |
213 | 213 | '@param null|object $query' |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | $createMethodBody = array_merge([ |
224 | 224 | '__construct' => 'self::$query = $query;', |
225 | 225 | '__get' => 'return static::{$name}();' |
226 | - ],$methodBodyList); |
|
226 | + ], $methodBodyList); |
|
227 | 227 | |
228 | 228 | $generator->createMethodBody($createMethodBody); |
229 | 229 |