@@ -17,13 +17,13 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | public function showTables() |
| 19 | 19 | { |
| 20 | - $tables = $this->connection()->query('SHOW TABLES')->fetchAll(); |
|
| 20 | + $tables = $this->connection()->query('SHOW TABLES')->fetchAll(); |
|
| 21 | 21 | |
| 22 | - $list = []; |
|
| 22 | + $list = []; |
|
| 23 | 23 | |
| 24 | 24 | foreach ($tables as $key=>$table) { |
| 25 | 25 | $list[] = $table[0]; |
| 26 | - } |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | return $list; |
| 29 | 29 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | { |
| 48 | 48 | $collation = $this->connection()->query('SHOW COLLATION LIKE \''.$collation.'%\'')->fetchAll(); |
| 49 | 49 | |
| 50 | - if(isset($collation[0])){ |
|
| 50 | + if (isset($collation[0])) { |
|
| 51 | 51 | return $collation[0]['Charset']; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | { |
| 65 | 65 | $status = $this->connection()->query('show table status like \''.$table.'\'')->fetchAll(); |
| 66 | 66 | |
| 67 | - if(isset($status[0])){ |
|
| 67 | + if (isset($status[0])) { |
|
| 68 | 68 | return $status[0]; |
| 69 | 69 | } |
| 70 | 70 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | WHERE rc.CONSTRAINT_SCHEMA = \''.$database.'\' |
| 101 | 101 | AND rc.TABLE_NAME = \''.$table.'\' AND r.REFERENCED_TABLE_NAME is not null')->fetchAll(); |
| 102 | 102 | |
| 103 | - if(isset($query[0])){ |
|
| 103 | + if (isset($query[0])) { |
|
| 104 | 104 | return $query[0]; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | { |
| 118 | 118 | try { |
| 119 | 119 | |
| 120 | - $query =$this->connection()->query($query); |
|
| 120 | + $query = $this->connection()->query($query); |
|
| 121 | 121 | |
| 122 | 122 | return [ |
| 123 | 123 | 'result'=>true, |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | 'message'=>null, |
| 126 | 126 | ]; |
| 127 | 127 | } |
| 128 | - catch (\PDOException $exception){ |
|
| 128 | + catch (\PDOException $exception) { |
|
| 129 | 129 | |
| 130 | 130 | return [ |
| 131 | 131 | 'result'=>false, |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | * Schema constructor. |
| 41 | 41 | * @param null|mixed $config |
| 42 | 42 | */ |
| 43 | - public function __construct($config=null) |
|
| 43 | + public function __construct($config = null) |
|
| 44 | 44 | { |
| 45 | 45 | $this->config = $config; |
| 46 | 46 | $this->driver = $this->config['database']['driver']; |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | * SchemaFacade constructor. |
| 29 | 29 | * @param array $config |
| 30 | 30 | */ |
| 31 | - public function __construct($config=array()) |
|
| 31 | + public function __construct($config = array()) |
|
| 32 | 32 | { |
| 33 | - if(count($config)){ |
|
| 33 | + if (count($config)) { |
|
| 34 | 34 | $this->schema = new Schema($config); |
| 35 | 35 | } |
| 36 | 36 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param array $params |
| 42 | 42 | * @return SchemaFacade |
| 43 | 43 | */ |
| 44 | - public static function setConfig($params=array()) |
|
| 44 | + public static function setConfig($params = array()) |
|
| 45 | 45 | { |
| 46 | 46 | self::$config = $params; |
| 47 | 47 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * @param array $tables |
| 55 | 55 | * @return SchemaFacade |
| 56 | 56 | */ |
| 57 | - public static function tables($tables=array()) |
|
| 57 | + public static function tables($tables = array()) |
|
| 58 | 58 | { |
| 59 | 59 | self::$tables = $tables; |
| 60 | 60 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public static function getInstance() |
| 70 | 70 | { |
| 71 | - if(is_null(self::$instance)){ |
|
| 71 | + if (is_null(self::$instance)) { |
|
| 72 | 72 | self::$instance = new self(self::$config); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | protected function getClassName($file) |
| 62 | 62 | { |
| 63 | - $className = str_replace(".php","",BaseRequestProcess::getFileName($file)); |
|
| 63 | + $className = str_replace(".php", "", BaseRequestProcess::getFileName($file)); |
|
| 64 | 64 | |
| 65 | 65 | return $className; |
| 66 | 66 | } |
@@ -100,11 +100,11 @@ discard block |
||
| 100 | 100 | * @param null|string $data |
| 101 | 101 | * @return mixed |
| 102 | 102 | */ |
| 103 | - public function queryBuilder($table=null,$data=null) |
|
| 103 | + public function queryBuilder($table = null, $data = null) |
|
| 104 | 104 | { |
| 105 | 105 | $queryBuilder = $this->queryBuilder; |
| 106 | 106 | |
| 107 | - return new $queryBuilder($this->schema,$table,$data); |
|
| 107 | + return new $queryBuilder($this->schema, $table, $data); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | foreach ($this->getAllFiles() as $table=>$allFile) { |
| 122 | 122 | |
| 123 | - if(count($tables)){ |
|
| 123 | + if (count($tables)) { |
|
| 124 | 124 | |
| 125 | - if(in_array($table,$tables)){ |
|
| 126 | - $list[$table]=$allFile; |
|
| 125 | + if (in_array($table, $tables)) { |
|
| 126 | + $list[$table] = $allFile; |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -136,15 +136,15 @@ discard block |
||
| 136 | 136 | * @param array $params |
| 137 | 137 | * @return mixed |
| 138 | 138 | */ |
| 139 | - public function getContentFile($path,$params=array()) |
|
| 139 | + public function getContentFile($path, $params = array()) |
|
| 140 | 140 | { |
| 141 | 141 | $dt = fopen($path, "r"); |
| 142 | 142 | $content = fread($dt, filesize($path)); |
| 143 | 143 | fclose($dt); |
| 144 | 144 | |
| 145 | - foreach ($params as $key=>$value){ |
|
| 145 | + foreach ($params as $key=>$value) { |
|
| 146 | 146 | |
| 147 | - $content=str_replace("__".$key."__",$value,$content); |
|
| 147 | + $content = str_replace("__".$key."__", $value, $content); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return $content; |
@@ -20,27 +20,27 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | $list = []; |
| 22 | 22 | |
| 23 | - foreach ($migrations as $table=>$item){ |
|
| 23 | + foreach ($migrations as $table=>$item) { |
|
| 24 | 24 | $list[] = strtolower($table); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - foreach ($dbtables as $dbtable){ |
|
| 27 | + foreach ($dbtables as $dbtable) { |
|
| 28 | 28 | //if(!in_array($dbtable,$list)){ |
| 29 | 29 | |
| 30 | 30 | $informations = $this->tableInformations($dbtable); |
| 31 | 31 | |
| 32 | 32 | $dbtable = ucfirst($dbtable); |
| 33 | 33 | $makeDirectory = $directory.''.DIRECTORY_SEPARATOR.''.$dbtable; |
| 34 | - files()->makeDirectory($makeDirectory,0755,true); |
|
| 34 | + files()->makeDirectory($makeDirectory, 0755, true); |
|
| 35 | 35 | |
| 36 | 36 | $migrationName = time().'_'.$dbtable.''; |
| 37 | 37 | |
| 38 | - $content = $this->getContentFile($this->getStubPath().''.DIRECTORY_SEPARATOR.'pullCreate.stub',[ |
|
| 38 | + $content = $this->getContentFile($this->getStubPath().''.DIRECTORY_SEPARATOR.'pullCreate.stub', [ |
|
| 39 | 39 | 'className' => $dbtable, |
| 40 | 40 | 'informations' => $informations |
| 41 | 41 | ]); |
| 42 | 42 | |
| 43 | - files()->put($makeDirectory.''.DIRECTORY_SEPARATOR.''.$migrationName.'.php',$content); |
|
| 43 | + files()->put($makeDirectory.''.DIRECTORY_SEPARATOR.''.$migrationName.'.php', $content); |
|
| 44 | 44 | //} |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -64,44 +64,44 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | $list = []; |
| 66 | 66 | |
| 67 | - foreach ($columns as $key=>$data){ |
|
| 67 | + foreach ($columns as $key=>$data) { |
|
| 68 | 68 | |
| 69 | 69 | $field = $data['Field']; |
| 70 | 70 | $list[] = '$wizard->name(\''.$field.'\')'; |
| 71 | 71 | $list[] = '->'.$this->getColumnTransformers($data['Type']).''; |
| 72 | 72 | |
| 73 | 73 | //default block |
| 74 | - if(!is_null($data['Default'])){ |
|
| 74 | + if (!is_null($data['Default'])) { |
|
| 75 | 75 | $default = $data['Default']; |
| 76 | - $list[] = '->default(\''.$default.'\')'; |
|
| 76 | + $list[] = '->default(\''.$default.'\')'; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - $getIndex = $this->getIndexInformation($indexes,$data['Field']); |
|
| 79 | + $getIndex = $this->getIndexInformation($indexes, $data['Field']); |
|
| 80 | 80 | |
| 81 | 81 | //unique block |
| 82 | - if($getIndex['Non_unique']=='0' && $getIndex['Key_name']!=='PRIMARY'){ |
|
| 82 | + if ($getIndex['Non_unique']=='0' && $getIndex['Key_name']!=='PRIMARY') { |
|
| 83 | 83 | $indexName = $getIndex['Key_name']; |
| 84 | - $list[] = '->unique(\''.$indexName.'\')'; |
|
| 84 | + $list[] = '->unique(\''.$indexName.'\')'; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | //index block |
| 88 | - if($getIndex['Non_unique']=='1' && $getIndex['Key_name']!=='PRIMARY'){ |
|
| 88 | + if ($getIndex['Non_unique']=='1' && $getIndex['Key_name']!=='PRIMARY') { |
|
| 89 | 89 | $columnName = $getIndex['Column_name']; |
| 90 | 90 | $indexName = $getIndex['Key_name']; |
| 91 | 91 | |
| 92 | - if(count($multipleIndexes[$indexName])==1){ |
|
| 92 | + if (count($multipleIndexes[$indexName])==1) { |
|
| 93 | 93 | $list[] = '->index(\''.$indexName.'\')'; |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | //comment block |
| 98 | - if(strlen($data['Comment'])>0){ |
|
| 98 | + if (strlen($data['Comment'])>0) { |
|
| 99 | 99 | $comment = $data['Comment']; |
| 100 | 100 | $list[] = '->comment(\''.$comment.'\')'; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | //auto increment block |
| 104 | - if($data['Extra']=='auto_increment'){ |
|
| 104 | + if ($data['Extra']=='auto_increment') { |
|
| 105 | 105 | $list[] = '->auto_increment()'; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -116,39 +116,39 @@ discard block |
||
| 116 | 116 | |
| 117 | 117 | //table indexes |
| 118 | 118 | foreach ($multipleIndexes as $indexName=>$values) { |
| 119 | - if(count($values)>1){ |
|
| 120 | - $values = '\''.implode('\',\'',$values).'\''; |
|
| 119 | + if (count($values)>1) { |
|
| 120 | + $values = '\''.implode('\',\'', $values).'\''; |
|
| 121 | 121 | $list[] = ' $wizard->table()->indexes(\''.$indexName.'\',['.$values.']); |
| 122 | 122 | '; |
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if(count($foreignKeys)){ |
|
| 126 | + if (count($foreignKeys)) { |
|
| 127 | 127 | |
| 128 | 128 | $constraintName = $foreignKeys['CONSTRAINT_NAME']; |
| 129 | 129 | $key = $foreignKeys['COLUMN_NAME']; |
| 130 | 130 | $referenceTable = $foreignKeys['REFERENCED_TABLE_NAME']; |
| 131 | 131 | $referenceColumn = $foreignKeys['REFERENCED_COLUMN_NAME']; |
| 132 | 132 | |
| 133 | - if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
|
| 133 | + if ($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT') { |
|
| 134 | 134 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\'); |
| 135 | 135 | '; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - if($foreignKeys['UPDATE_RULE']!=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT'){ |
|
| 138 | + if ($foreignKeys['UPDATE_RULE']!=='RESTRICT' && $foreignKeys['DELETE_RULE']=='RESTRICT') { |
|
| 139 | 139 | $rule = $foreignKeys['UPDATE_RULE']; |
| 140 | 140 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onUpdate()->'.strtolower($rule).'(); |
| 141 | 141 | '; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']!=='RESTRICT'){ |
|
| 144 | + if ($foreignKeys['UPDATE_RULE']=='RESTRICT' && $foreignKeys['DELETE_RULE']!=='RESTRICT') { |
|
| 145 | 145 | $rule = $foreignKeys['DELETE_RULE']; |
| 146 | 146 | $list[] = ' $wizard->table()->foreign()->constraint(\''.$constraintName.'\')->key(\''.$key.'\')->references(\''.$referenceTable.'\',\''.$referenceColumn.'\')->onDelete()->'.strtolower($rule).'(); |
| 147 | 147 | '; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - return implode('',$list); |
|
| 151 | + return implode('', $list); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -159,19 +159,19 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | private function getColumnTransformers($column) |
| 161 | 161 | { |
| 162 | - if($column=='datetime'){ |
|
| 162 | + if ($column=='datetime') { |
|
| 163 | 163 | return 'datetime()'; |
| 164 | 164 | } |
| 165 | - elseif($column=='longtext'){ |
|
| 165 | + elseif ($column=='longtext') { |
|
| 166 | 166 | return 'longtext()'; |
| 167 | 167 | } |
| 168 | - elseif($column=='date'){ |
|
| 168 | + elseif ($column=='date') { |
|
| 169 | 169 | return 'date()'; |
| 170 | 170 | } |
| 171 | - elseif(preg_match('@enum.*\((.*?)\)@',$column,$enum)){ |
|
| 171 | + elseif (preg_match('@enum.*\((.*?)\)@', $column, $enum)) { |
|
| 172 | 172 | return 'enum(['.$enum[1].'])'; |
| 173 | 173 | } |
| 174 | - else{ |
|
| 174 | + else { |
|
| 175 | 175 | return $column; |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | * @param $field |
| 184 | 184 | * @return void|mixed |
| 185 | 185 | */ |
| 186 | - private function getIndexInformation($index,$field) |
|
| 186 | + private function getIndexInformation($index, $field) |
|
| 187 | 187 | { |
| 188 | 188 | foreach ($index as $key=>$item) { |
| 189 | 189 | |
| 190 | - if($item['Column_name'] == $field){ |
|
| 190 | + if ($item['Column_name']==$field) { |
|
| 191 | 191 | return $index[$key]; |
| 192 | 192 | } |
| 193 | 193 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | { |
| 207 | 207 | $list = []; |
| 208 | 208 | foreach ($index as $key=>$item) { |
| 209 | - if($item['Non_unique']==1 && $item['Key_name']!=='PRIMARY'){ |
|
| 209 | + if ($item['Non_unique']==1 && $item['Key_name']!=='PRIMARY') { |
|
| 210 | 210 | $list[$item['Key_name']][] = $item['Column_name']; |
| 211 | 211 | } |
| 212 | 212 | } |
@@ -161,17 +161,13 @@ |
||
| 161 | 161 | { |
| 162 | 162 | if($column=='datetime'){ |
| 163 | 163 | return 'datetime()'; |
| 164 | - } |
|
| 165 | - elseif($column=='longtext'){ |
|
| 164 | + } elseif($column=='longtext'){ |
|
| 166 | 165 | return 'longtext()'; |
| 167 | - } |
|
| 168 | - elseif($column=='date'){ |
|
| 166 | + } elseif($column=='date'){ |
|
| 169 | 167 | return 'date()'; |
| 170 | - } |
|
| 171 | - elseif(preg_match('@enum.*\((.*?)\)@',$column,$enum)){ |
|
| 168 | + } elseif(preg_match('@enum.*\((.*?)\)@',$column,$enum)){ |
|
| 172 | 169 | return 'enum(['.$enum[1].'])'; |
| 173 | - } |
|
| 174 | - else{ |
|
| 170 | + } else{ |
|
| 175 | 171 | return $column; |
| 176 | 172 | } |
| 177 | 173 | } |
@@ -11,17 +11,17 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | public function processHandler() |
| 13 | 13 | { |
| 14 | - return $this->errorHandler(function(){ |
|
| 14 | + return $this->errorHandler(function() { |
|
| 15 | 15 | |
| 16 | - foreach ($this->list as $table =>$datas){ |
|
| 16 | + foreach ($this->list as $table =>$datas) { |
|
| 17 | 17 | |
| 18 | - foreach ($datas as $data){ |
|
| 18 | + foreach ($datas as $data) { |
|
| 19 | 19 | |
| 20 | - $query = $this->queryBuilder($table,$data); |
|
| 20 | + $query = $this->queryBuilder($table, $data); |
|
| 21 | 21 | |
| 22 | 22 | $query = $query->handle(); |
| 23 | 23 | |
| 24 | - $results[]= [ |
|
| 24 | + $results[] = [ |
|
| 25 | 25 | 'success'=>$status, |
| 26 | 26 | 'file'=>$data->getFile(), |
| 27 | 27 | 'table'=>$table, |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | { |
| 49 | 49 | foreach ($objects as $object) |
| 50 | 50 | { |
| 51 | - if(count($object->getError())){ |
|
| 51 | + if (count($object->getError())) { |
|
| 52 | 52 | return 'error : '.$object->getFile().' -> '.$object->getError()[0].''; |
| 53 | 53 | } |
| 54 | 54 | } |
@@ -22,18 +22,18 @@ |
||
| 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 | |
| 29 | 29 | foreach ($files as $file) { |
| 30 | 30 | |
| 31 | - $getClassName = preg_replace('@(\d+)_@is','',$file); |
|
| 31 | + $getClassName = preg_replace('@(\d+)_@is', '', $file); |
|
| 32 | 32 | $className = $this->getClassName($getClassName); |
| 33 | 33 | |
| 34 | 34 | require_once ($file); |
| 35 | 35 | |
| 36 | - $capsule = new SchemaCapsule($this->config,$file,$table); |
|
| 36 | + $capsule = new SchemaCapsule($this->config, $file, $table); |
|
| 37 | 37 | |
| 38 | 38 | $this->list[$table][] = (new $className)->up($capsule); |
| 39 | 39 | } |
@@ -29,14 +29,14 @@ |
||
| 29 | 29 | { |
| 30 | 30 | $this->config = $config; |
| 31 | 31 | |
| 32 | - if(is_null(self::$instance)){ |
|
| 32 | + if (is_null(self::$instance)) { |
|
| 33 | 33 | |
| 34 | 34 | //get pdo dsn |
| 35 | - $dsn=''.$config['driver'].':host='.$config['host'].';dbname='.$config['database'].''; |
|
| 35 | + $dsn = ''.$config['driver'].':host='.$config['host'].';dbname='.$config['database'].''; |
|
| 36 | 36 | $this->connection = new \PDO($dsn, $config['user'], $config['password']); |
| 37 | 37 | $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
| 38 | 38 | |
| 39 | - self::$instance=true; |
|
| 39 | + self::$instance = true; |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | |