@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | public function append($value) |
| 9 | 9 | { |
| 10 | 10 | //Make sure we're adding a TableDumper object |
| 11 | - if(!($value instanceof TableDumper)) { |
|
| 11 | + if (!($value instanceof TableDumper)) { |
|
| 12 | 12 | throw new \Exception("TableDumperCollection only accepts TableDumper objects", 1); |
| 13 | 13 | } |
| 14 | 14 | |
@@ -18,16 +18,16 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | public function addTable($table) |
| 20 | 20 | { |
| 21 | - if($table instanceof Table) { |
|
| 21 | + if ($table instanceof Table) { |
|
| 22 | 22 | $tableName = $table->getName(); |
| 23 | - } elseif(is_string($table)) { |
|
| 23 | + } elseif (is_string($table)) { |
|
| 24 | 24 | $tableName = $table; |
| 25 | 25 | } else { |
| 26 | 26 | throw new \Exception("Invalid value supplied for argument 'table'", 1); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | //First check if a dumper already exists for this table |
| 30 | - if(!$this->offsetExists($tableName)) { |
|
| 30 | + if (!$this->offsetExists($tableName)) { |
|
| 31 | 31 | //Create new one |
| 32 | 32 | $table = new Table($tableName); |
| 33 | 33 | $this->offsetSet($tableName, new TableDumper($table)); |
@@ -39,20 +39,20 @@ discard block |
||
| 39 | 39 | public function addListTables($listTables) |
| 40 | 40 | { |
| 41 | 41 | //If arg is a TableDumperCollection, merge into this one |
| 42 | - if($listTables instanceof TableDumperCollection) { |
|
| 42 | + if ($listTables instanceof TableDumperCollection) { |
|
| 43 | 43 | foreach ($listTables as $table) { |
| 44 | 44 | $this->append($table); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | return $listTables; |
| 48 | 48 | } |
| 49 | - elseif(is_array($listTables)) { |
|
| 49 | + elseif (is_array($listTables)) { |
|
| 50 | 50 | //Create TableDumperCollection |
| 51 | 51 | $listDumpers = new TableDumperCollection; |
| 52 | 52 | |
| 53 | 53 | foreach ($listTables as $table) { |
| 54 | 54 | //If table is already a Dumper, simply append to this |
| 55 | - if($table instanceof TableDumper) { |
|
| 55 | + if ($table instanceof TableDumper) { |
|
| 56 | 56 | $listDumpers[] = $table; |
| 57 | 57 | $this->append($table); |
| 58 | 58 | } else { |
@@ -66,8 +66,7 @@ |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | return $listTables; |
| 69 | - } |
|
| 70 | - elseif(is_array($listTables)) { |
|
| 69 | + } elseif(is_array($listTables)) { |
|
| 71 | 70 | //Create TableDumperCollection |
| 72 | 71 | $listDumpers = new TableDumperCollection; |
| 73 | 72 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | protected function dumpDropStatement(PDO $db, $stream) |
| 60 | 60 | { |
| 61 | - fwrite($stream, 'DROP TABLE IF EXISTS `'.$this->table->getName(). "`;\r\n"); |
|
| 61 | + fwrite($stream, 'DROP TABLE IF EXISTS `'.$this->table->getName()."`;\r\n"); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | protected function dumpInsertStatement(PDO $db, $stream) |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | //Get data from table |
| 67 | 67 | $select = 'SELECT * FROM '.$this->table->getName(); |
| 68 | 68 | |
| 69 | - if(!empty($this->where)) { |
|
| 69 | + if (!empty($this->where)) { |
|
| 70 | 70 | $select .= ' WHERE '.$this->where; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | $stmt->bindValue(':offset', $i*$limit, PDO::PARAM_INT); |
| 86 | 86 | $stmt->execute(); |
| 87 | 87 | |
| 88 | - while(($row = $stmt->fetch(PDO::FETCH_ASSOC)) !== false) { |
|
| 88 | + while (($row = $stmt->fetch(PDO::FETCH_ASSOC)) !== false) { |
|
| 89 | 89 | //Write start of INSERT statement |
| 90 | - if($j === 0) { |
|
| 90 | + if ($j === 0) { |
|
| 91 | 91 | //Gets keys from array indexes of first row |
| 92 | 92 | $fields = implode(',', array_keys($row)); |
| 93 | 93 | |
@@ -97,16 +97,16 @@ discard block |
||
| 97 | 97 | //Write values of this row |
| 98 | 98 | $valuesDump = ''; |
| 99 | 99 | |
| 100 | - if($j > 0) { |
|
| 100 | + if ($j > 0) { |
|
| 101 | 101 | $valuesDump .= ", \r\n"; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $listValues = array_values($row); |
| 105 | 105 | |
| 106 | 106 | //Quote values or replace with NULL if null |
| 107 | - foreach($listValues as $key => $value) { |
|
| 107 | + foreach ($listValues as $key => $value) { |
|
| 108 | 108 | $quotedValue = str_replace("'", "\'", str_replace('"', '\"', $value)); |
| 109 | - $listValues[$key] = (!isset($value) ? 'NULL' : "'" . $quotedValue."'") ; |
|
| 109 | + $listValues[$key] = (!isset($value) ? 'NULL' : "'".$quotedValue."'"); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | //Add values from this row to valuesDump |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | $stmt->closeCursor(); |
| 120 | 120 | $i++; |
| 121 | 121 | |
| 122 | - } while($j === $i*$limit); |
|
| 122 | + } while ($j === $i*$limit); |
|
| 123 | 123 | |
| 124 | 124 | //If there was at least one row, write end of INSERT statement |
| 125 | - if($j > 0) { |
|
| 125 | + if ($j > 0) { |
|
| 126 | 126 | fwrite($stream, ";\r\n"); |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -130,17 +130,17 @@ discard block |
||
| 130 | 130 | public function dump(PDO $db, $stream) |
| 131 | 131 | { |
| 132 | 132 | //Drop table statement |
| 133 | - if($this->withDrop) { |
|
| 133 | + if ($this->withDrop) { |
|
| 134 | 134 | $this->dumpDropStatement($db, $stream); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | //Create table statement |
| 138 | - if($this->withStructure) { |
|
| 138 | + if ($this->withStructure) { |
|
| 139 | 139 | $this->dumpCreateStatement($db, $stream); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | //Data |
| 143 | - if($this->withData) { |
|
| 143 | + if ($this->withData) { |
|
| 144 | 144 | $this->dumpInsertStatement($db, $stream); |
| 145 | 145 | } |
| 146 | 146 | } |