@@ -14,41 +14,41 @@ 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 | - $this->schema->getConnection()->registerMigration($table,$data->getFile()); |
|
| 29 | + $this->schema->getConnection()->registerMigration($table, $data->getFile()); |
|
| 30 | 30 | |
| 31 | - if($query===false){ |
|
| 31 | + if ($query===false) { |
|
| 32 | 32 | $results[] = []; |
| 33 | 33 | } |
| 34 | - else{ |
|
| 35 | - $status =($query['result']!==false) ? true : false; |
|
| 34 | + else { |
|
| 35 | + $status = ($query['result']!==false) ? true : false; |
|
| 36 | 36 | |
| 37 | - if($status){ |
|
| 37 | + if ($status) { |
|
| 38 | 38 | |
| 39 | 39 | //$this->schema->getConnection()->registerMigration($table,$data->getFile()); |
| 40 | 40 | |
| 41 | 41 | //$this->schema->getConnection()->generateEntity($table); |
| 42 | 42 | |
| 43 | - if(substr($table,-1)=='s'){ |
|
| 43 | + if (substr($table, -1)=='s') { |
|
| 44 | 44 | //app()->command('model create','model:'.strtolower(substr($table,0,-1)).' table:'.$table.' entity:'.$table); |
| 45 | 45 | } |
| 46 | - else{ |
|
| 46 | + else { |
|
| 47 | 47 | //app()->command('model create','model:'.strtolower($table).' table:'.$table.' entity:'.$table); |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - $results[]= [ |
|
| 51 | + $results[] = [ |
|
| 52 | 52 | 'success'=>$status, |
| 53 | 53 | 'file'=>$data->getFile(), |
| 54 | 54 | 'table'=>$table, |
@@ -78,11 +78,11 @@ discard block |
||
| 78 | 78 | { |
| 79 | 79 | $alterBinds = $object->getAlterBinds(); |
| 80 | 80 | |
| 81 | - if(!is_null($alterBinds) && count($alterBinds)>1){ |
|
| 81 | + if (!is_null($alterBinds) && count($alterBinds)>1) { |
|
| 82 | 82 | exception()->runtime('Only one command can be applied to alter groups'); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if(count($object->getError())){ |
|
| 85 | + if (count($object->getError())) { |
|
| 86 | 86 | exception()->runtime(''.$object->getFile().' -> '.$object->getError()[0].''); |
| 87 | 87 | } |
| 88 | 88 | |
@@ -30,8 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | if($query===false){ |
| 32 | 32 | $results[] = []; |
| 33 | - } |
|
| 34 | - else{ |
|
| 33 | + } else{ |
|
| 35 | 34 | $status =($query['result']!==false) ? true : false; |
| 36 | 35 | |
| 37 | 36 | if($status){ |
@@ -42,8 +41,7 @@ discard block |
||
| 42 | 41 | |
| 43 | 42 | if(substr($table,-1)=='s'){ |
| 44 | 43 | //app()->command('model create','model:'.strtolower(substr($table,0,-1)).' table:'.$table.' entity:'.$table); |
| 45 | - } |
|
| 46 | - else{ |
|
| 44 | + } else{ |
|
| 47 | 45 | //app()->command('model create','model:'.strtolower($table).' table:'.$table.' entity:'.$table); |
| 48 | 46 | } |
| 49 | 47 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | public function handle() |
| 24 | 24 | { |
| 25 | - foreach ($this->tableFilters() as $table=>$files){ |
|
| 25 | + foreach ($this->tableFilters() as $table=>$files) { |
|
| 26 | 26 | |
| 27 | 27 | $table = strtolower($table); |
| 28 | 28 | |
@@ -30,20 +30,20 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | $checkMigrationMain = $this->schema->getConnection()->checkMigrationMain(); |
| 32 | 32 | |
| 33 | - if($checkMigrationMain===false && isset($this->tableFilters()['Migrations'][0])){ |
|
| 34 | - $this->apply($this->tableFilters()['Migrations'][0],'migrations'); |
|
| 33 | + if ($checkMigrationMain===false && isset($this->tableFilters()['Migrations'][0])) { |
|
| 34 | + $this->apply($this->tableFilters()['Migrations'][0], 'migrations'); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - $checkMigration = $this->schema->getConnection()->checkMigration($table,$file); |
|
| 37 | + $checkMigration = $this->schema->getConnection()->checkMigration($table, $file); |
|
| 38 | 38 | |
| 39 | - if(!$checkMigration){ |
|
| 39 | + if (!$checkMigration) { |
|
| 40 | 40 | |
| 41 | - $getClassName = preg_replace('@(\d+)_@is','',$file); |
|
| 41 | + $getClassName = preg_replace('@(\d+)_@is', '', $file); |
|
| 42 | 42 | $className = $this->getClassName($getClassName); |
| 43 | 43 | |
| 44 | 44 | require_once ($file); |
| 45 | 45 | |
| 46 | - $capsule = new SchemaCapsule($this->config,$file,$table); |
|
| 46 | + $capsule = new SchemaCapsule($this->config, $file, $table); |
|
| 47 | 47 | |
| 48 | 48 | $this->list[$table][] = (new $className)->up($capsule); |
| 49 | 49 | } |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | * @param $table |
| 61 | 61 | * @return mixed|string |
| 62 | 62 | */ |
| 63 | - public function apply($file,$table) |
|
| 63 | + public function apply($file, $table) |
|
| 64 | 64 | { |
| 65 | - $getClassName = preg_replace('@(\d+)_@is','',$file); |
|
| 65 | + $getClassName = preg_replace('@(\d+)_@is', '', $file); |
|
| 66 | 66 | $className = $this->getClassName($getClassName); |
| 67 | 67 | |
| 68 | 68 | require_once ($file); |
| 69 | 69 | |
| 70 | - $capsule = new SchemaCapsule($this->config,$file,$table); |
|
| 70 | + $capsule = new SchemaCapsule($this->config, $file, $table); |
|
| 71 | 71 | |
| 72 | 72 | $this->list[$table][] = (new $className)->up($capsule); |
| 73 | 73 | |
@@ -15,14 +15,14 @@ discard block |
||
| 15 | 15 | return $this->schema->getConnection(); |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public function registerMigration($table,$name) |
|
| 18 | + public function registerMigration($table, $name) |
|
| 19 | 19 | { |
| 20 | 20 | return $this->connection()->query( |
| 21 | 21 | "INSERT INTO migrations SET table_name ='".$table."',name='".$name."' |
| 22 | 22 | "); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - public function checkMigration($table,$name) |
|
| 25 | + public function checkMigration($table, $name) |
|
| 26 | 26 | { |
| 27 | 27 | $query = $this->connection()->query( |
| 28 | 28 | "SELECT * FROM migrations WHERE table_name='".$table."' and name='".$name."' |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | public function checkMigrationMain() |
| 35 | 35 | { |
| 36 | - return (in_array('migrations',$this->showTables())) ? true : false; |
|
| 36 | + return (in_array('migrations', $this->showTables())) ? true : false; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | $collation = $this->connection()->query('SHOW COLLATION LIKE \''.$collation.'%\'')->fetchAll(); |
| 73 | 73 | |
| 74 | - if(isset($collation[0])){ |
|
| 74 | + if (isset($collation[0])) { |
|
| 75 | 75 | return $collation[0]['Charset']; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | { |
| 89 | 89 | $status = $this->connection()->query('show table status like \''.$table.'\'')->fetchAll(); |
| 90 | 90 | |
| 91 | - if(isset($status[0])){ |
|
| 91 | + if (isset($status[0])) { |
|
| 92 | 92 | return $status[0]; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | WHERE rc.CONSTRAINT_SCHEMA = \''.$database.'\' |
| 125 | 125 | AND rc.TABLE_NAME = \''.$table.'\' AND r.REFERENCED_TABLE_NAME is not null')->fetchAll(); |
| 126 | 126 | |
| 127 | - if(isset($query[0])){ |
|
| 127 | + if (isset($query[0])) { |
|
| 128 | 128 | return $query[0]; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | { |
| 142 | 142 | try { |
| 143 | 143 | |
| 144 | - $query =$this->connection()->query($query); |
|
| 144 | + $query = $this->connection()->query($query); |
|
| 145 | 145 | |
| 146 | 146 | return [ |
| 147 | 147 | 'result'=>true, |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | 'message'=>null, |
| 150 | 150 | ]; |
| 151 | 151 | } |
| 152 | - catch (\PDOException $exception){ |
|
| 152 | + catch (\PDOException $exception) { |
|
| 153 | 153 | |
| 154 | 154 | return [ |
| 155 | 155 | 'result'=>false, |
@@ -165,15 +165,15 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | public function generateEntity($table) |
| 167 | 167 | { |
| 168 | - if(in_array($table,$this->showTables()) || in_array($table = strtolower($table),$this->showTables())){ |
|
| 168 | + if (in_array($table, $this->showTables()) || in_array($table = strtolower($table), $this->showTables())) { |
|
| 169 | 169 | |
| 170 | 170 | $entityDirectory = path()->model().''.DIRECTORY_SEPARATOR.'Entity'; |
| 171 | 171 | |
| 172 | - if(!file_exists(app()->path()->model())){ |
|
| 172 | + if (!file_exists(app()->path()->model())) { |
|
| 173 | 173 | files()->makeDirectory(app()->path()->model()); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if(!file_exists($entityDirectory)){ |
|
| 176 | + if (!file_exists($entityDirectory)) { |
|
| 177 | 177 | files()->makeDirectory($entityDirectory); |
| 178 | 178 | } |
| 179 | 179 | |
@@ -185,27 +185,27 @@ discard block |
||
| 185 | 185 | $list[] = $column['Field']; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - if(!file_exists($entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table))){ |
|
| 189 | - $generator = new Generator($entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table),$table.''); |
|
| 188 | + if (!file_exists($entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table))) { |
|
| 189 | + $generator = new Generator($entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table), $table.''); |
|
| 190 | 190 | $generator->createClass(); |
| 191 | 191 | } |
| 192 | - else{ |
|
| 193 | - $generator = new Generator($entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table),$table.''); |
|
| 192 | + else { |
|
| 193 | + $generator = new Generator($entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table), $table.''); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
| 197 | 197 | $abstractClassPath = $entityDirectory.''.DIRECTORY_SEPARATOR.''.ucfirst($table).''.DIRECTORY_SEPARATOR.'Entity'; |
| 198 | 198 | $abstractNamespace = Utils::getNamespace($abstractClassPath.''.DIRECTORY_SEPARATOR.''.ucfirst($table).'Abstract'); |
| 199 | 199 | |
| 200 | - $generator->createClassExtend($abstractNamespace,ucfirst($table).'Abstract'); |
|
| 200 | + $generator->createClassExtend($abstractNamespace, ucfirst($table).'Abstract'); |
|
| 201 | 201 | |
| 202 | - $generator = new Generator($abstractClassPath,$table.'Abstract'); |
|
| 202 | + $generator = new Generator($abstractClassPath, $table.'Abstract'); |
|
| 203 | 203 | |
| 204 | 204 | $generator->createClass(); |
| 205 | 205 | |
| 206 | - $method =array_merge([ |
|
| 206 | + $method = array_merge([ |
|
| 207 | 207 | '__construct' |
| 208 | - ],array_merge($list,['__get'])); |
|
| 208 | + ], array_merge($list, ['__get'])); |
|
| 209 | 209 | |
| 210 | 210 | $generator->createMethod($method); |
| 211 | 211 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | |
| 231 | 231 | $generator->createClassDocument($createClassDocument); |
| 232 | 232 | |
| 233 | - $generator->createMethodDocument(array_merge($createMethodDocument,[ |
|
| 233 | + $generator->createMethodDocument(array_merge($createMethodDocument, [ |
|
| 234 | 234 | '__construct' => [ |
| 235 | 235 | ''.$table.' constructor.', |
| 236 | 236 | '@param null|object $query' |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $createMethodBody = array_merge([ |
| 247 | 247 | '__construct' => 'self::$query = $query;', |
| 248 | 248 | '__get' => 'return static::{$name}();' |
| 249 | - ],$methodBodyList); |
|
| 249 | + ], $methodBodyList); |
|
| 250 | 250 | |
| 251 | 251 | $generator->createMethodBody($createMethodBody); |
| 252 | 252 | |