@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @type \Classes\Db\DbTable[][] |
| 59 | 59 | */ |
| 60 | - protected $objDbTables = array (); |
|
| 60 | + protected $objDbTables = array(); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * @var AbstractAdapter |
@@ -72,19 +72,19 @@ discard block |
||
| 72 | 72 | /** |
| 73 | 73 | * Popula as ForeingKeys do banco nos objetos |
| 74 | 74 | */ |
| 75 | - protected abstract function parseForeignKeys (); |
|
| 75 | + protected abstract function parseForeignKeys(); |
|
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * cria um Array com nome das tabelas |
| 79 | 79 | */ |
| 80 | - protected abstract function parseTables (); |
|
| 80 | + protected abstract function parseTables(); |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * retorna o numero total de tabelas |
| 84 | 84 | * |
| 85 | 85 | * @return int |
| 86 | 86 | */ |
| 87 | - public abstract function getTotalTables (); |
|
| 87 | + public abstract function getTotalTables(); |
|
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * Retorna o Nome da Sequence da tabela |
@@ -94,23 +94,23 @@ discard block |
||
| 94 | 94 | * |
| 95 | 95 | * @return string |
| 96 | 96 | */ |
| 97 | - public abstract function getSequence ( $table , $column ); |
|
| 97 | + public abstract function getSequence($table, $column); |
|
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * @return array |
| 101 | 101 | */ |
| 102 | - public abstract function getListConstrant (); |
|
| 102 | + public abstract function getListConstrant(); |
|
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | 105 | * @param string $str |
| 106 | 106 | * |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - protected function convertTypeToPhp ( $str ) |
|
| 109 | + protected function convertTypeToPhp($str) |
|
| 110 | 110 | { |
| 111 | - if ( isset( $this->dataTypes[ $str ] ) ) |
|
| 111 | + if (isset($this->dataTypes[$str])) |
|
| 112 | 112 | { |
| 113 | - return $this->dataTypes[ $str ]; |
|
| 113 | + return $this->dataTypes[$str]; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | return 'string'; |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | /** |
| 120 | 120 | * @return string |
| 121 | 121 | */ |
| 122 | - public abstract function getPDOString (); |
|
| 122 | + public abstract function getPDOString(); |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * @return string |
| 126 | 126 | */ |
| 127 | - public abstract function getPDOSocketString (); |
|
| 127 | + public abstract function getPDOSocketString(); |
|
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * @param $nameTable |
@@ -132,13 +132,13 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @return \Classes\Db\DbTable |
| 134 | 134 | */ |
| 135 | - public function createTable ( $nameTable , $schema = 0 ) |
|
| 135 | + public function createTable($nameTable, $schema = 0) |
|
| 136 | 136 | { |
| 137 | - $this->objDbTables[ $schema ][ trim ( $nameTable ) ] = new DbTable(); |
|
| 138 | - $this->objDbTables[ $schema ][ trim ( $nameTable ) ]->populate ( |
|
| 139 | - array ( |
|
| 140 | - 'table' => $nameTable , |
|
| 141 | - 'schema' => $schema , |
|
| 137 | + $this->objDbTables[$schema][trim($nameTable)] = new DbTable(); |
|
| 138 | + $this->objDbTables[$schema][trim($nameTable)]->populate( |
|
| 139 | + array( |
|
| 140 | + 'table' => $nameTable, |
|
| 141 | + 'schema' => $schema, |
|
| 142 | 142 | 'database' => $this->database |
| 143 | 143 | ) |
| 144 | 144 | ); |
@@ -151,14 +151,14 @@ discard block |
||
| 151 | 151 | * |
| 152 | 152 | * @return \Classes\Db\DbTable[] |
| 153 | 153 | */ |
| 154 | - public function getTables ( $schema = 0 ) |
|
| 154 | + public function getTables($schema = 0) |
|
| 155 | 155 | { |
| 156 | - if ( ! isset( $this->objDbTables[ $schema ] ) ) |
|
| 156 | + if ( ! isset($this->objDbTables[$schema])) |
|
| 157 | 157 | { |
| 158 | - return array (); |
|
| 158 | + return array(); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - return $this->objDbTables[ $schema ]; |
|
| 161 | + return $this->objDbTables[$schema]; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @return \Classes\Db\DbTable|null |
| 170 | 170 | */ |
| 171 | - public function getTable ( $nameTable , $schema = 0 ) |
|
| 171 | + public function getTable($nameTable, $schema = 0) |
|
| 172 | 172 | { |
| 173 | - if ( isset( $this->objDbTables[ $schema ][ trim ( $nameTable ) ] ) ) |
|
| 173 | + if (isset($this->objDbTables[$schema][trim($nameTable)])) |
|
| 174 | 174 | { |
| 175 | - return $this->objDbTables[ $schema ][ trim ( $nameTable ) ]; |
|
| 175 | + return $this->objDbTables[$schema][trim($nameTable)]; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return null; |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return bool |
| 186 | 186 | */ |
| 187 | - public function hasTable ( $nameTable , $schema = 0 ) |
|
| 187 | + public function hasTable($nameTable, $schema = 0) |
|
| 188 | 188 | { |
| 189 | - if ( isset( $this->objDbTables[ $schema ][ trim ( $nameTable ) ] ) ) |
|
| 189 | + if (isset($this->objDbTables[$schema][trim($nameTable)])) |
|
| 190 | 190 | { |
| 191 | 191 | return true; |
| 192 | 192 | } |
@@ -199,64 +199,64 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return array[] |
| 201 | 201 | */ |
| 202 | - public abstract function getListColumns (); |
|
| 202 | + public abstract function getListColumns(); |
|
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | 205 | * Retorna um Array com nome das tabelas |
| 206 | 206 | * |
| 207 | 207 | * @return string[] |
| 208 | 208 | */ |
| 209 | - public abstract function getListNameTable (); |
|
| 209 | + public abstract function getListNameTable(); |
|
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | 212 | * @param \Classes\AdapterConfig\AbstractAdapter $adapterConfig |
| 213 | 213 | */ |
| 214 | - public function __construct ( AbstractAdapter $adapterConfig ) |
|
| 214 | + public function __construct(AbstractAdapter $adapterConfig) |
|
| 215 | 215 | { |
| 216 | 216 | $this->config = $adapterConfig; |
| 217 | - $this->host = $adapterConfig->getHost (); |
|
| 218 | - $this->database = $adapterConfig->getDatabase (); |
|
| 219 | - $this->port = $adapterConfig->hasPort () ? $adapterConfig->getPort () |
|
| 217 | + $this->host = $adapterConfig->getHost(); |
|
| 218 | + $this->database = $adapterConfig->getDatabase(); |
|
| 219 | + $this->port = $adapterConfig->hasPort() ? $adapterConfig->getPort() |
|
| 220 | 220 | : $this->port; |
| 221 | - $this->username = $adapterConfig->getUser (); |
|
| 222 | - $this->password = $adapterConfig->getPassword (); |
|
| 223 | - $this->socket = $adapterConfig->getSocket (); |
|
| 221 | + $this->username = $adapterConfig->getUser(); |
|
| 222 | + $this->password = $adapterConfig->getPassword(); |
|
| 223 | + $this->socket = $adapterConfig->getSocket(); |
|
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
| 228 | 228 | * Executa as consultas do banco de dados |
| 229 | 229 | */ |
| 230 | - public function runDatabase () |
|
| 230 | + public function runDatabase() |
|
| 231 | 231 | { |
| 232 | - $this->parseTables (); |
|
| 233 | - $this->parseForeignKeys (); |
|
| 232 | + $this->parseTables(); |
|
| 233 | + $this->parseForeignKeys(); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | 237 | * |
| 238 | 238 | * @return \PDO |
| 239 | 239 | */ |
| 240 | - public function getPDO () |
|
| 240 | + public function getPDO() |
|
| 241 | 241 | { |
| 242 | - if ( is_null ( $this->_pdo ) ) |
|
| 242 | + if (is_null($this->_pdo)) |
|
| 243 | 243 | { |
| 244 | - if ( ! empty( $this->socket ) ) |
|
| 244 | + if ( ! empty($this->socket)) |
|
| 245 | 245 | { |
| 246 | - $pdoString = $this->getPDOSocketString (); |
|
| 246 | + $pdoString = $this->getPDOSocketString(); |
|
| 247 | 247 | } else |
| 248 | 248 | { |
| 249 | - $pdoString = $this->getPDOString (); |
|
| 249 | + $pdoString = $this->getPDOString(); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | try |
| 253 | 253 | { |
| 254 | - $this->_pdo = new \PDO ( |
|
| 255 | - $pdoString , $this->username , $this->password |
|
| 254 | + $this->_pdo = new \PDO( |
|
| 255 | + $pdoString, $this->username, $this->password |
|
| 256 | 256 | ); |
| 257 | - } catch ( \Exception $e ) |
|
| 257 | + } catch (\Exception $e) |
|
| 258 | 258 | { |
| 259 | - die ( "pdo error: " . $e->getMessage () . "\n" ); |
|
| 259 | + die ("pdo error: " . $e->getMessage() . "\n"); |
|
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
@@ -27,43 +27,43 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @type array|\string[] |
| 29 | 29 | */ |
| 30 | - protected $schema = array ( 'public' ); |
|
| 30 | + protected $schema = array('public'); |
|
| 31 | 31 | |
| 32 | - protected $dataTypes = array ( |
|
| 32 | + protected $dataTypes = array( |
|
| 33 | 33 | /* Numeric Types */ |
| 34 | - 'smallint' => 'int' , |
|
| 35 | - 'integer' => 'int' , |
|
| 36 | - 'bigint' => 'float' , |
|
| 37 | - 'decimal' => 'float' , |
|
| 38 | - 'numeric' => 'float' , |
|
| 39 | - 'real' => 'float' , |
|
| 40 | - 'double precision' => 'float' , |
|
| 41 | - 'serial' => 'int' , |
|
| 42 | - 'bigserial' => 'float' , |
|
| 34 | + 'smallint' => 'int', |
|
| 35 | + 'integer' => 'int', |
|
| 36 | + 'bigint' => 'float', |
|
| 37 | + 'decimal' => 'float', |
|
| 38 | + 'numeric' => 'float', |
|
| 39 | + 'real' => 'float', |
|
| 40 | + 'double precision' => 'float', |
|
| 41 | + 'serial' => 'int', |
|
| 42 | + 'bigserial' => 'float', |
|
| 43 | 43 | /* Monetary Types */ |
| 44 | - 'money' => 'float' , |
|
| 44 | + 'money' => 'float', |
|
| 45 | 45 | /* Character Types */ |
| 46 | - 'character varyin' => 'string' , |
|
| 47 | - 'varchar' => 'string' , |
|
| 48 | - 'character' => 'string' , |
|
| 49 | - 'char' => 'string' , |
|
| 50 | - 'text' => 'string' , |
|
| 46 | + 'character varyin' => 'string', |
|
| 47 | + 'varchar' => 'string', |
|
| 48 | + 'character' => 'string', |
|
| 49 | + 'char' => 'string', |
|
| 50 | + 'text' => 'string', |
|
| 51 | 51 | /* Binary Data Types */ |
| 52 | - 'bytea' => 'string' , |
|
| 52 | + 'bytea' => 'string', |
|
| 53 | 53 | /* Date/Time Types */ |
| 54 | - 'datatime' => 'date' , |
|
| 55 | - 'date' => 'date' , |
|
| 54 | + 'datatime' => 'date', |
|
| 55 | + 'date' => 'date', |
|
| 56 | 56 | |
| 57 | 57 | /* Boolean Type */ |
| 58 | 58 | 'boolean' => 'boolean' |
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | - public function __construct ( AbstractAdapter $adapterConfig ) |
|
| 61 | + public function __construct(AbstractAdapter $adapterConfig) |
|
| 62 | 62 | { |
| 63 | - parent::__construct ( $adapterConfig ); |
|
| 64 | - if ( $adapterConfig->hasSchemas () ) |
|
| 63 | + parent::__construct($adapterConfig); |
|
| 64 | + if ($adapterConfig->hasSchemas()) |
|
| 65 | 65 | { |
| 66 | - $this->schema = $adapterConfig->getSchemas (); |
|
| 66 | + $this->schema = $adapterConfig->getSchemas(); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | } |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return string[] |
| 77 | 77 | */ |
| 78 | - public function getListNameTable () |
|
| 78 | + public function getListNameTable() |
|
| 79 | 79 | { |
| 80 | - if ( empty( $this->tableList ) ) |
|
| 80 | + if (empty($this->tableList)) |
|
| 81 | 81 | { |
| 82 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 82 | + $strSchema = implode("', '", $this->schema); |
|
| 83 | 83 | |
| 84 | - $this->tableList = $this->getPDO ()->query ( |
|
| 84 | + $this->tableList = $this->getPDO()->query( |
|
| 85 | 85 | "SELECT table_schema, table_name |
| 86 | 86 | FROM information_schema.tables |
| 87 | 87 | WHERE |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | table_schema, |
| 92 | 92 | table_name |
| 93 | 93 | ASC" |
| 94 | - )->fetchAll (); |
|
| 94 | + )->fetchAll(); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return $this->tableList; |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @return array |
| 104 | 104 | */ |
| 105 | - public function getListColumns () |
|
| 105 | + public function getListColumns() |
|
| 106 | 106 | { |
| 107 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 107 | + $strSchema = implode("', '", $this->schema); |
|
| 108 | 108 | |
| 109 | - return $this->getPDO ()->query ( |
|
| 109 | + return $this->getPDO()->query( |
|
| 110 | 110 | "SELECT distinct |
| 111 | 111 | c.table_schema, |
| 112 | 112 | c.table_name, |
@@ -120,14 +120,14 @@ discard block |
||
| 120 | 120 | ON st.table_name=c.table_name and st.table_type = 'BASE TABLE' |
| 121 | 121 | and c.table_schema IN ('$strSchema') |
| 122 | 122 | order by c.table_name asc" |
| 123 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 123 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function getListConstrant () |
|
| 126 | + public function getListConstrant() |
|
| 127 | 127 | { |
| 128 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 128 | + $strSchema = implode("', '", $this->schema); |
|
| 129 | 129 | |
| 130 | - return $this->getPDO ()->query ( |
|
| 130 | + return $this->getPDO()->query( |
|
| 131 | 131 | "SELECT distinct |
| 132 | 132 | tc.constraint_type, |
| 133 | 133 | tc.constraint_name, |
@@ -147,50 +147,50 @@ discard block |
||
| 147 | 147 | ON tc.constraint_name = ccu.constraint_name |
| 148 | 148 | AND tc.constraint_schema = ccu.constraint_schema |
| 149 | 149 | ORDER by tc.table_schema" |
| 150 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 150 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * @inheritDoc |
| 155 | 155 | */ |
| 156 | - public function parseForeignKeys () |
|
| 156 | + public function parseForeignKeys() |
|
| 157 | 157 | { |
| 158 | - foreach ( $this->getListConstrant () as $constrant ) |
|
| 158 | + foreach ($this->getListConstrant() as $constrant) |
|
| 159 | 159 | { |
| 160 | - if ( $constrant[ 'constraint_type' ] == "FOREIGN KEY" |
|
| 161 | - || $constrant[ 'constraint_type' ] == "PRIMARY KEY" |
|
| 160 | + if ($constrant['constraint_type'] == "FOREIGN KEY" |
|
| 161 | + || $constrant['constraint_type'] == "PRIMARY KEY" |
|
| 162 | 162 | ) |
| 163 | 163 | { |
| 164 | - $schema = $constrant[ 'table_schema' ]; |
|
| 165 | - $key = $constrant [ 'table_name' ]; |
|
| 166 | - if ( $this->hasTable ( $key , $schema ) ) |
|
| 164 | + $schema = $constrant['table_schema']; |
|
| 165 | + $key = $constrant ['table_name']; |
|
| 166 | + if ($this->hasTable($key, $schema)) |
|
| 167 | 167 | { |
| 168 | - $column = $this->getTable ( $key , $schema ) |
|
| 169 | - ->getColumn ( $constrant[ "column_name" ] ); |
|
| 170 | - if ( $column ) |
|
| 168 | + $column = $this->getTable($key, $schema) |
|
| 169 | + ->getColumn($constrant["column_name"]); |
|
| 170 | + if ($column) |
|
| 171 | 171 | { |
| 172 | 172 | $objConstrant = new Constrant(); |
| 173 | - $objConstrant->populate ( |
|
| 174 | - array ( |
|
| 175 | - 'constrant' => $constrant[ 'constraint_name' ] , |
|
| 176 | - 'schema' => $constrant[ 'foreign_schema' ] , |
|
| 177 | - 'table' => $constrant[ 'foreign_table' ] , |
|
| 178 | - 'column' => $constrant[ 'foreign_column' ] |
|
| 173 | + $objConstrant->populate( |
|
| 174 | + array( |
|
| 175 | + 'constrant' => $constrant['constraint_name'], |
|
| 176 | + 'schema' => $constrant['foreign_schema'], |
|
| 177 | + 'table' => $constrant['foreign_table'], |
|
| 178 | + 'column' => $constrant['foreign_column'] |
|
| 179 | 179 | ) |
| 180 | 180 | ); |
| 181 | 181 | |
| 182 | 182 | |
| 183 | - switch ( $constrant[ 'constraint_type' ] ) |
|
| 183 | + switch ($constrant['constraint_type']) |
|
| 184 | 184 | { |
| 185 | 185 | case "FOREIGN KEY": |
| 186 | - $column->addRefFk ( $objConstrant ); |
|
| 186 | + $column->addRefFk($objConstrant); |
|
| 187 | 187 | break; |
| 188 | 188 | case"PRIMARY KEY": |
| 189 | - $column->setPrimaryKey ( $objConstrant ); |
|
| 190 | - $column->setSequence ( |
|
| 191 | - $this->getSequence ( |
|
| 192 | - $schema . '.' . $key , |
|
| 193 | - $constrant[ "column_name" ] |
|
| 189 | + $column->setPrimaryKey($objConstrant); |
|
| 190 | + $column->setSequence( |
|
| 191 | + $this->getSequence( |
|
| 192 | + $schema . '.' . $key, |
|
| 193 | + $constrant["column_name"] |
|
| 194 | 194 | ) |
| 195 | 195 | ); |
| 196 | 196 | |
@@ -198,29 +198,29 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | - unset( $key , $column ); |
|
| 201 | + unset($key, $column); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - if ( $constrant[ 'constraint_type' ] == "FOREIGN KEY" ) |
|
| 204 | + if ($constrant['constraint_type'] == "FOREIGN KEY") |
|
| 205 | 205 | { |
| 206 | - $schema = $constrant[ 'foreign_schema' ]; |
|
| 207 | - $key = $constrant [ 'foreign_table' ]; |
|
| 208 | - if ( $this->hasTable ( $key , $schema ) ) |
|
| 206 | + $schema = $constrant['foreign_schema']; |
|
| 207 | + $key = $constrant ['foreign_table']; |
|
| 208 | + if ($this->hasTable($key, $schema)) |
|
| 209 | 209 | { |
| 210 | - $column = $this->getTable ( $key , $schema ) |
|
| 211 | - ->getColumn ( $constrant[ "foreign_column" ] ); |
|
| 210 | + $column = $this->getTable($key, $schema) |
|
| 211 | + ->getColumn($constrant["foreign_column"]); |
|
| 212 | 212 | |
| 213 | - if ( $column ) |
|
| 213 | + if ($column) |
|
| 214 | 214 | { |
| 215 | - $column->createDependece ( |
|
| 216 | - $constrant[ 'constraint_name' ] , |
|
| 217 | - $constrant[ 'table_name' ] , |
|
| 218 | - $constrant[ 'column_name' ] , |
|
| 219 | - $constrant[ 'table_schema' ] |
|
| 215 | + $column->createDependece( |
|
| 216 | + $constrant['constraint_name'], |
|
| 217 | + $constrant['table_name'], |
|
| 218 | + $constrant['column_name'], |
|
| 219 | + $constrant['table_schema'] |
|
| 220 | 220 | ); |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | - unset( $key , $column ); |
|
| 223 | + unset($key, $column); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -235,20 +235,20 @@ discard block |
||
| 235 | 235 | * |
| 236 | 236 | * @return string |
| 237 | 237 | */ |
| 238 | - public function getSequence ( $table , $column ) |
|
| 238 | + public function getSequence($table, $column) |
|
| 239 | 239 | { |
| 240 | - $pdo = $this->getPDO (); |
|
| 241 | - $return1 = $pdo->query ( "SELECT pg_get_serial_sequence('$table', '$column');" ) |
|
| 242 | - ->fetchColumn (); |
|
| 240 | + $pdo = $this->getPDO(); |
|
| 241 | + $return1 = $pdo->query("SELECT pg_get_serial_sequence('$table', '$column');") |
|
| 242 | + ->fetchColumn(); |
|
| 243 | 243 | |
| 244 | - if ( $return1 ) |
|
| 244 | + if ($return1) |
|
| 245 | 245 | { |
| 246 | 246 | return $return1; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - $dtbase = explode ( '.' , $table );; |
|
| 249 | + $dtbase = explode('.', $table); ; |
|
| 250 | 250 | |
| 251 | - $stmt = $pdo->prepare ( |
|
| 251 | + $stmt = $pdo->prepare( |
|
| 252 | 252 | "SELECT adsrc FROM pg_attrdef AS att |
| 253 | 253 | INNER JOIN pg_class AS c |
| 254 | 254 | ON adrelid = c.oid AND att.adnum=1 AND c.relname = ? |
@@ -256,19 +256,19 @@ discard block |
||
| 256 | 256 | ON n.oid = c.relnamespace and n.nspname=?" |
| 257 | 257 | ); |
| 258 | 258 | |
| 259 | - $schema = isset( $dtbase[ 1 ] ) ? $dtbase[ 1 ] : 'public'; |
|
| 259 | + $schema = isset($dtbase[1]) ? $dtbase[1] : 'public'; |
|
| 260 | 260 | |
| 261 | - $stmt->bindParam ( 1 , $schema ); |
|
| 262 | - $stmt->bindParam ( 2 , $dtbase[ 0 ] ); |
|
| 263 | - $stmt->execute (); |
|
| 264 | - $return2 = $stmt->fetchColumn (); |
|
| 265 | - if ( $return2 ) |
|
| 261 | + $stmt->bindParam(1, $schema); |
|
| 262 | + $stmt->bindParam(2, $dtbase[0]); |
|
| 263 | + $stmt->execute(); |
|
| 264 | + $return2 = $stmt->fetchColumn(); |
|
| 265 | + if ($return2) |
|
| 266 | 266 | { |
| 267 | - return preg_filter ( |
|
| 268 | - array ( |
|
| 269 | - '/nextval\(\'/' , |
|
| 267 | + return preg_filter( |
|
| 268 | + array( |
|
| 269 | + '/nextval\(\'/', |
|
| 270 | 270 | '/\'::regclass\)/' |
| 271 | - ) , '' , $return2 |
|
| 271 | + ), '', $return2 |
|
| 272 | 272 | ); |
| 273 | 273 | } |
| 274 | 274 | |
@@ -277,36 +277,36 @@ discard block |
||
| 277 | 277 | /** |
| 278 | 278 | * @inheritDoc |
| 279 | 279 | */ |
| 280 | - public function parseTables () |
|
| 280 | + public function parseTables() |
|
| 281 | 281 | { |
| 282 | - if ( ! empty( $this->objDbTables ) ) |
|
| 282 | + if ( ! empty($this->objDbTables)) |
|
| 283 | 283 | { |
| 284 | 284 | return $this->objDbTables; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - foreach ( $this->getListColumns () as $table ) |
|
| 287 | + foreach ($this->getListColumns() as $table) |
|
| 288 | 288 | { |
| 289 | - $schema = $table[ 'table_schema' ]; |
|
| 290 | - $key = $table [ 'table_name' ]; |
|
| 291 | - if ( ! $this->hasTable ( $key , $schema ) ) |
|
| 289 | + $schema = $table['table_schema']; |
|
| 290 | + $key = $table ['table_name']; |
|
| 291 | + if ( ! $this->hasTable($key, $schema)) |
|
| 292 | 292 | { |
| 293 | - $this->createTable ( $key , $schema ); |
|
| 293 | + $this->createTable($key, $schema); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | - $this->getTable ( $key , $schema ) |
|
| 297 | - ->createColumn ( $table [ 'column_name' ] ) |
|
| 298 | - ->getColumn ( $table [ 'column_name' ] ) |
|
| 299 | - ->populate ( |
|
| 300 | - array ( |
|
| 301 | - 'name' => $table [ 'column_name' ] , |
|
| 302 | - 'type' => $this->convertTypeToPhp ( $table[ 'data_type' ] ) , |
|
| 303 | - 'nullable' => ( $table[ 'is_nullable' ] == 'YES' ) , |
|
| 304 | - 'max_length' => $table[ 'max_length' ] |
|
| 296 | + $this->getTable($key, $schema) |
|
| 297 | + ->createColumn($table ['column_name']) |
|
| 298 | + ->getColumn($table ['column_name']) |
|
| 299 | + ->populate( |
|
| 300 | + array( |
|
| 301 | + 'name' => $table ['column_name'], |
|
| 302 | + 'type' => $this->convertTypeToPhp($table['data_type']), |
|
| 303 | + 'nullable' => ($table['is_nullable'] == 'YES'), |
|
| 304 | + 'max_length' => $table['max_length'] |
|
| 305 | 305 | ) |
| 306 | 306 | ); |
| 307 | 307 | |
| 308 | - $this->getTable ( $key , $schema )->setNamespace ( |
|
| 309 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 308 | + $this->getTable($key, $schema)->setNamespace( |
|
| 309 | + $this->config->createClassNamespace($this->getTable($key, $schema)) |
|
| 310 | 310 | ); |
| 311 | 311 | } |
| 312 | 312 | |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | * @inheritDoc |
| 317 | 317 | * @return string |
| 318 | 318 | */ |
| 319 | - public function getPDOString () |
|
| 319 | + public function getPDOString() |
|
| 320 | 320 | { |
| 321 | - return sprintf ( |
|
| 322 | - "pgsql:host=%s;port=%s;dbname=%s" , |
|
| 323 | - $this->host , |
|
| 324 | - $this->port , |
|
| 321 | + return sprintf( |
|
| 322 | + "pgsql:host=%s;port=%s;dbname=%s", |
|
| 323 | + $this->host, |
|
| 324 | + $this->port, |
|
| 325 | 325 | $this->database |
| 326 | 326 | |
| 327 | 327 | ); |
@@ -331,11 +331,11 @@ discard block |
||
| 331 | 331 | * @inheritDoc |
| 332 | 332 | * @return string |
| 333 | 333 | */ |
| 334 | - public function getPDOSocketString () |
|
| 334 | + public function getPDOSocketString() |
|
| 335 | 335 | { |
| 336 | - return sprintf ( |
|
| 337 | - "pgsql:unix_socket=%s;dbname=%s" , |
|
| 338 | - $this->socket , |
|
| 336 | + return sprintf( |
|
| 337 | + "pgsql:unix_socket=%s;dbname=%s", |
|
| 338 | + $this->socket, |
|
| 339 | 339 | $this->database |
| 340 | 340 | |
| 341 | 341 | ); |
@@ -346,19 +346,19 @@ discard block |
||
| 346 | 346 | * |
| 347 | 347 | * @return int |
| 348 | 348 | */ |
| 349 | - public function getTotalTables () |
|
| 349 | + public function getTotalTables() |
|
| 350 | 350 | { |
| 351 | - if ( empty( $this->totalTables ) ) |
|
| 351 | + if (empty($this->totalTables)) |
|
| 352 | 352 | { |
| 353 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 353 | + $strSchema = implode("', '", $this->schema); |
|
| 354 | 354 | |
| 355 | - $this->totalTables = $this->getPDO ()->query ( |
|
| 355 | + $this->totalTables = $this->getPDO()->query( |
|
| 356 | 356 | "SELECT COUNT(table_name) AS total |
| 357 | 357 | FROM information_schema.tables |
| 358 | 358 | WHERE |
| 359 | 359 | table_type = 'BASE TABLE' |
| 360 | 360 | AND table_schema IN ( '" . $strSchema . "' )" |
| 361 | - )->fetchColumn (); |
|
| 361 | + )->fetchColumn(); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | return (int) $this->totalTables; |
@@ -30,20 +30,20 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - protected function convertTypeToPhp ( $str ) |
|
| 33 | + protected function convertTypeToPhp($str) |
|
| 34 | 34 | { |
| 35 | - if ( preg_match ( '/(tinyint\(1\)|bit)/' , $str ) ) |
|
| 35 | + if (preg_match('/(tinyint\(1\)|bit)/', $str)) |
|
| 36 | 36 | { |
| 37 | 37 | $res = 'boolean'; |
| 38 | - } elseif ( preg_match ( '/(datetime|timestamp|blob|char|enum|text|date)/' , $str ) ) |
|
| 38 | + } elseif (preg_match('/(datetime|timestamp|blob|char|enum|text|date)/', $str)) |
|
| 39 | 39 | { |
| 40 | 40 | $res = 'string'; |
| 41 | - } elseif ( preg_match ( '/(decimal|numeric|float|double)/' , $str ) ) |
|
| 41 | + } elseif (preg_match('/(decimal|numeric|float|double)/', $str)) |
|
| 42 | 42 | { |
| 43 | 43 | $res = 'float'; |
| 44 | - } elseif ( preg_match ( '#^(?:tiny|small|medium|long|big|var)?(\w+)(?:\(\d+\))?(?:\s\w+)*$#' , $str , $matches ) ) |
|
| 44 | + } elseif (preg_match('#^(?:tiny|small|medium|long|big|var)?(\w+)(?:\(\d+\))?(?:\s\w+)*$#', $str, $matches)) |
|
| 45 | 45 | { |
| 46 | - $res = $matches[ 1 ]; |
|
| 46 | + $res = $matches[1]; |
|
| 47 | 47 | } else |
| 48 | 48 | { |
| 49 | 49 | print "Can't convert column type to PHP - Unrecognized type: $str"; |
@@ -55,44 +55,44 @@ discard block |
||
| 55 | 55 | /** |
| 56 | 56 | * @inheritDoc |
| 57 | 57 | */ |
| 58 | - protected function parseForeignKeys () |
|
| 58 | + protected function parseForeignKeys() |
|
| 59 | 59 | { |
| 60 | 60 | $schema = 0; |
| 61 | - foreach ( $this->getListConstrant () as $constrant ) |
|
| 61 | + foreach ($this->getListConstrant() as $constrant) |
|
| 62 | 62 | { |
| 63 | 63 | |
| 64 | - if ( $constrant[ 'constraint_type' ] == "FOREIGN KEY" |
|
| 65 | - || $constrant[ 'constraint_type' ] == "PRIMARY KEY" |
|
| 64 | + if ($constrant['constraint_type'] == "FOREIGN KEY" |
|
| 65 | + || $constrant['constraint_type'] == "PRIMARY KEY" |
|
| 66 | 66 | ) |
| 67 | 67 | { |
| 68 | - $key = $constrant [ 'table_name' ]; |
|
| 69 | - if ( $this->hasTable ( $key , $schema ) ) |
|
| 68 | + $key = $constrant ['table_name']; |
|
| 69 | + if ($this->hasTable($key, $schema)) |
|
| 70 | 70 | { |
| 71 | - $column = $this->getTable ( $key , $schema ) |
|
| 72 | - ->getColumn ( $constrant[ "column_name" ] ); |
|
| 73 | - if ( $column ) |
|
| 71 | + $column = $this->getTable($key, $schema) |
|
| 72 | + ->getColumn($constrant["column_name"]); |
|
| 73 | + if ($column) |
|
| 74 | 74 | { |
| 75 | 75 | $objConstrant = new Constrant(); |
| 76 | - $objConstrant->populate ( |
|
| 77 | - array ( |
|
| 78 | - 'constrant' => $constrant[ 'constraint_name' ] , |
|
| 79 | - 'table' => $constrant[ 'foreign_table' ] , |
|
| 80 | - 'column' => $constrant[ 'foreign_column' ] |
|
| 76 | + $objConstrant->populate( |
|
| 77 | + array( |
|
| 78 | + 'constrant' => $constrant['constraint_name'], |
|
| 79 | + 'table' => $constrant['foreign_table'], |
|
| 80 | + 'column' => $constrant['foreign_column'] |
|
| 81 | 81 | ) |
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | 84 | |
| 85 | - switch ( $constrant[ 'constraint_type' ] ) |
|
| 85 | + switch ($constrant['constraint_type']) |
|
| 86 | 86 | { |
| 87 | 87 | case "FOREIGN KEY": |
| 88 | - $column->addRefFk ( $objConstrant ); |
|
| 88 | + $column->addRefFk($objConstrant); |
|
| 89 | 89 | break; |
| 90 | 90 | case"PRIMARY KEY": |
| 91 | - $column->setPrimaryKey ( $objConstrant ); |
|
| 92 | - $column->setSequence ( |
|
| 93 | - $this->getSequence ( |
|
| 94 | - $key , |
|
| 95 | - $constrant[ "column_name" ] |
|
| 91 | + $column->setPrimaryKey($objConstrant); |
|
| 92 | + $column->setSequence( |
|
| 93 | + $this->getSequence( |
|
| 94 | + $key, |
|
| 95 | + $constrant["column_name"] |
|
| 96 | 96 | ) |
| 97 | 97 | ); |
| 98 | 98 | |
@@ -100,28 +100,28 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | - unset( $key , $column ); |
|
| 103 | + unset($key, $column); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if ( $constrant[ 'constraint_type' ] == "FOREIGN KEY" ) |
|
| 106 | + if ($constrant['constraint_type'] == "FOREIGN KEY") |
|
| 107 | 107 | { |
| 108 | - $key = $constrant [ 'foreign_table' ]; |
|
| 109 | - if ( $this->hasTable ( $key , $schema ) ) |
|
| 108 | + $key = $constrant ['foreign_table']; |
|
| 109 | + if ($this->hasTable($key, $schema)) |
|
| 110 | 110 | { |
| 111 | - $column = $this->getTable ( $key , $schema ) |
|
| 112 | - ->getColumn ( $constrant[ "foreign_column" ] ); |
|
| 111 | + $column = $this->getTable($key, $schema) |
|
| 112 | + ->getColumn($constrant["foreign_column"]); |
|
| 113 | 113 | |
| 114 | - if ( $column ) |
|
| 114 | + if ($column) |
|
| 115 | 115 | { |
| 116 | - $column->createDependece ( |
|
| 117 | - $constrant[ 'constraint_name' ] , |
|
| 118 | - $constrant[ 'table_name' ] , |
|
| 119 | - $constrant[ 'column_name' ] , |
|
| 120 | - $constrant[ 'table_schema' ] |
|
| 116 | + $column->createDependece( |
|
| 117 | + $constrant['constraint_name'], |
|
| 118 | + $constrant['table_name'], |
|
| 119 | + $constrant['column_name'], |
|
| 120 | + $constrant['table_schema'] |
|
| 121 | 121 | ); |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | - unset( $key , $column ); |
|
| 124 | + unset($key, $column); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -134,36 +134,36 @@ discard block |
||
| 134 | 134 | /** |
| 135 | 135 | * @inheritDoc |
| 136 | 136 | */ |
| 137 | - public function parseTables () |
|
| 137 | + public function parseTables() |
|
| 138 | 138 | { |
| 139 | - if ( ! empty( $this->objDbTables ) ) |
|
| 139 | + if ( ! empty($this->objDbTables)) |
|
| 140 | 140 | { |
| 141 | 141 | return $this->objDbTables; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | $schema = 0; |
| 145 | - foreach ( $this->getListColumns () as $table ) |
|
| 145 | + foreach ($this->getListColumns() as $table) |
|
| 146 | 146 | { |
| 147 | - $key = $table [ 'table_name' ]; |
|
| 148 | - if ( ! $this->hasTable ( $key , $schema ) ) |
|
| 147 | + $key = $table ['table_name']; |
|
| 148 | + if ( ! $this->hasTable($key, $schema)) |
|
| 149 | 149 | { |
| 150 | - $this->createTable ( $key , $schema ); |
|
| 150 | + $this->createTable($key, $schema); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $this->getTable ( $key , $schema ) |
|
| 154 | - ->createColumn ( $table [ 'column_name' ] ) |
|
| 155 | - ->getColumn ( $table [ 'column_name' ] ) |
|
| 156 | - ->populate ( |
|
| 157 | - array ( |
|
| 158 | - 'name' => $table [ 'column_name' ] , |
|
| 159 | - 'type' => $this->convertTypeToPhp ( $table[ 'data_type' ] ) , |
|
| 160 | - 'nullable' => ( $table[ 'is_nullable' ] == 'YES' ) , |
|
| 161 | - 'max_length' => $table[ 'max_length' ] |
|
| 153 | + $this->getTable($key, $schema) |
|
| 154 | + ->createColumn($table ['column_name']) |
|
| 155 | + ->getColumn($table ['column_name']) |
|
| 156 | + ->populate( |
|
| 157 | + array( |
|
| 158 | + 'name' => $table ['column_name'], |
|
| 159 | + 'type' => $this->convertTypeToPhp($table['data_type']), |
|
| 160 | + 'nullable' => ($table['is_nullable'] == 'YES'), |
|
| 161 | + 'max_length' => $table['max_length'] |
|
| 162 | 162 | ) |
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | - $this->getTable ( $key , $schema )->setNamespace ( |
|
| 166 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 165 | + $this->getTable($key, $schema)->setNamespace( |
|
| 166 | + $this->config->createClassNamespace($this->getTable($key, $schema)) |
|
| 167 | 167 | ); |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -172,12 +172,12 @@ discard block |
||
| 172 | 172 | * @inheritDoc |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function getPDOString () |
|
| 175 | + public function getPDOString() |
|
| 176 | 176 | { |
| 177 | - return sprintf ( |
|
| 178 | - "mysql:host=%s;port=%s;dbname=%s" , |
|
| 179 | - $this->host , |
|
| 180 | - $this->port , |
|
| 177 | + return sprintf( |
|
| 178 | + "mysql:host=%s;port=%s;dbname=%s", |
|
| 179 | + $this->host, |
|
| 180 | + $this->port, |
|
| 181 | 181 | $this->database |
| 182 | 182 | |
| 183 | 183 | ); |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | * @inheritDoc |
| 188 | 188 | * @return string |
| 189 | 189 | */ |
| 190 | - public function getPDOSocketString () |
|
| 190 | + public function getPDOSocketString() |
|
| 191 | 191 | { |
| 192 | - return sprintf ( |
|
| 193 | - "mysql:unix_socket=%s;dbname=%s" , |
|
| 194 | - $this->socket , |
|
| 192 | + return sprintf( |
|
| 193 | + "mysql:unix_socket=%s;dbname=%s", |
|
| 194 | + $this->socket, |
|
| 195 | 195 | $this->database |
| 196 | 196 | |
| 197 | 197 | ); |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | * @inheritDoc |
| 202 | 202 | * @return string[] |
| 203 | 203 | */ |
| 204 | - public function getListNameTable () |
|
| 204 | + public function getListNameTable() |
|
| 205 | 205 | { |
| 206 | - if ( empty( $this->tableList ) ) |
|
| 206 | + if (empty($this->tableList)) |
|
| 207 | 207 | { |
| 208 | - $this->tableList = $this->getPDO ()->query ( |
|
| 208 | + $this->tableList = $this->getPDO()->query( |
|
| 209 | 209 | "show tables" |
| 210 | - )->fetchAll (); |
|
| 210 | + )->fetchAll(); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | return $this->tableList; |
@@ -218,10 +218,10 @@ discard block |
||
| 218 | 218 | * |
| 219 | 219 | * @return array[] |
| 220 | 220 | */ |
| 221 | - public function getListColumns () |
|
| 221 | + public function getListColumns() |
|
| 222 | 222 | { |
| 223 | 223 | |
| 224 | - return $this->getPDO ()->query ( |
|
| 224 | + return $this->getPDO()->query( |
|
| 225 | 225 | "select |
| 226 | 226 | table_schema, |
| 227 | 227 | table_name, |
@@ -232,15 +232,15 @@ discard block |
||
| 232 | 232 | from information_schema.columns |
| 233 | 233 | where table_schema IN ('{$this->database}') |
| 234 | 234 | order by table_name,ordinal_position" |
| 235 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 235 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
| 239 | 239 | * @return array |
| 240 | 240 | */ |
| 241 | - public function getListConstrant () |
|
| 241 | + public function getListConstrant() |
|
| 242 | 242 | { |
| 243 | - return $this->getPDO ()->query ( |
|
| 243 | + return $this->getPDO()->query( |
|
| 244 | 244 | "SELECT distinct |
| 245 | 245 | i.constraint_type, |
| 246 | 246 | k.constraint_name, |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | WHERE |
| 257 | 257 | i.TABLE_SCHEMA IN ('{$this->database}') AND i.CONSTRAINT_TYPE IN ('FOREIGN KEY', 'PRIMARY KEY' ) |
| 258 | 258 | order by k.table_schema, k.table_name;" |
| 259 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 259 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | * |
| 265 | 265 | * @return int |
| 266 | 266 | */ |
| 267 | - public function getTotalTables () |
|
| 267 | + public function getTotalTables() |
|
| 268 | 268 | { |
| 269 | - if ( empty( $this->totalTables ) ) |
|
| 269 | + if (empty($this->totalTables)) |
|
| 270 | 270 | { |
| 271 | 271 | |
| 272 | - $this->totalTables = $this->getPDO ()->query ( |
|
| 272 | + $this->totalTables = $this->getPDO()->query( |
|
| 273 | 273 | "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '{$this->database}'" |
| 274 | - )->fetchColumn (); |
|
| 274 | + )->fetchColumn(); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | return (int) $this->totalTables; |
@@ -283,13 +283,13 @@ discard block |
||
| 283 | 283 | * @param $table |
| 284 | 284 | * @param $column |
| 285 | 285 | */ |
| 286 | - public function getSequence ( $table , $column ) |
|
| 286 | + public function getSequence($table, $column) |
|
| 287 | 287 | { |
| 288 | - $return = $this->getPDO () |
|
| 289 | - ->query ( "select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';" ) |
|
| 290 | - ->fetch ( \PDO::FETCH_ASSOC ); |
|
| 288 | + $return = $this->getPDO() |
|
| 289 | + ->query("select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';") |
|
| 290 | + ->fetch(\PDO::FETCH_ASSOC); |
|
| 291 | 291 | |
| 292 | - if ( ! $return ) |
|
| 292 | + if ( ! $return) |
|
| 293 | 293 | { |
| 294 | 294 | return; |
| 295 | 295 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | /** |
| 12 | 12 | * @author Pedro Alarcao <[email protected]> |
| 13 | 13 | */ |
| 14 | - public function __construct () |
|
| 14 | + public function __construct() |
|
| 15 | 15 | { |
| 16 | 16 | } |
| 17 | 17 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | /** |
| 34 | 34 | * @var \Classes\Db\Column[] |
| 35 | 35 | */ |
| 36 | - private $columns = array (); |
|
| 36 | + private $columns = array(); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * @var string |
@@ -43,25 +43,25 @@ discard block |
||
| 43 | 43 | /** |
| 44 | 44 | * @type \Classes\Db\Column[] |
| 45 | 45 | */ |
| 46 | - private $primarykeys = array (); |
|
| 46 | + private $primarykeys = array(); |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * @type \Classes\Db\Column[] |
| 50 | 50 | */ |
| 51 | - private $foreingkeys = array (); |
|
| 51 | + private $foreingkeys = array(); |
|
| 52 | 52 | |
| 53 | - private $dependence = array (); |
|
| 53 | + private $dependence = array(); |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * @type string[] |
| 57 | 57 | */ |
| 58 | - private $sequence = array (); |
|
| 58 | + private $sequence = array(); |
|
| 59 | 59 | |
| 60 | - public function populate ( $array ) |
|
| 60 | + public function populate($array) |
|
| 61 | 61 | { |
| 62 | - $this->name = $array[ 'table' ]; |
|
| 63 | - $this->schema = isset( $array[ 'schema' ] ) ? $array[ 'schema' ] : null; |
|
| 64 | - $this->database = $array[ 'database' ]; |
|
| 62 | + $this->name = $array['table']; |
|
| 63 | + $this->schema = isset($array['schema']) ? $array['schema'] : null; |
|
| 64 | + $this->database = $array['database']; |
|
| 65 | 65 | |
| 66 | 66 | return $this; |
| 67 | 67 | } |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | /** |
| 70 | 70 | * @param \Classes\Db\Column $column |
| 71 | 71 | */ |
| 72 | - public function addColumn ( Column $column ) |
|
| 72 | + public function addColumn(Column $column) |
|
| 73 | 73 | { |
| 74 | - $this->columns[ $column->getName () ] = $column; |
|
| 74 | + $this->columns[$column->getName()] = $column; |
|
| 75 | 75 | |
| 76 | 76 | return $this; |
| 77 | 77 | } |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @return $this |
| 83 | 83 | */ |
| 84 | - public function createColumn ( $columnName ) |
|
| 84 | + public function createColumn($columnName) |
|
| 85 | 85 | { |
| 86 | - $this->columns[ $columnName ] = new Column(); |
|
| 86 | + $this->columns[$columnName] = new Column(); |
|
| 87 | 87 | |
| 88 | 88 | return $this; |
| 89 | 89 | } |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @return \Classes\Db\Column |
| 95 | 95 | */ |
| 96 | - public function getColumn ( $columnName ) |
|
| 96 | + public function getColumn($columnName) |
|
| 97 | 97 | { |
| 98 | - if ( isset( $this->columns[ $columnName ] ) ) |
|
| 98 | + if (isset($this->columns[$columnName])) |
|
| 99 | 99 | { |
| 100 | - return $this->columns[ $columnName ]; |
|
| 100 | + return $this->columns[$columnName]; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | return; |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | /** |
| 107 | 107 | * @return \Classes\Db\Column[] |
| 108 | 108 | */ |
| 109 | - public function getPrimaryKeys () |
|
| 109 | + public function getPrimaryKeys() |
|
| 110 | 110 | { |
| 111 | - if ( empty ( $this->primarykeys ) ) |
|
| 111 | + if (empty ($this->primarykeys)) |
|
| 112 | 112 | { |
| 113 | - $this->primarykeys = array_filter ( $this->columns , function ( $column ){ return $column->isPrimaryKey (); } ); |
|
| 113 | + $this->primarykeys = array_filter($this->columns, function($column) { return $column->isPrimaryKey(); } ); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | return $this->primarykeys; |
@@ -119,25 +119,25 @@ discard block |
||
| 119 | 119 | /** |
| 120 | 120 | * @return bool |
| 121 | 121 | */ |
| 122 | - public function hasPrimaryKey () |
|
| 122 | + public function hasPrimaryKey() |
|
| 123 | 123 | { |
| 124 | - if ( empty ( $this->sequence ) ) |
|
| 124 | + if (empty ($this->sequence)) |
|
| 125 | 125 | { |
| 126 | - $this->getPrimaryKeys (); |
|
| 126 | + $this->getPrimaryKeys(); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - return ! empty ( $this->sequence ); |
|
| 129 | + return ! empty ($this->sequence); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | 133 | * @return \Classes\Db\Column[] |
| 134 | 134 | */ |
| 135 | - public function getForeingkeys () |
|
| 135 | + public function getForeingkeys() |
|
| 136 | 136 | { |
| 137 | 137 | |
| 138 | - if ( empty ( $this->foreingkeys ) ) |
|
| 138 | + if (empty ($this->foreingkeys)) |
|
| 139 | 139 | { |
| 140 | - $this->foreingkeys = array_filter ( $this->columns , function ( $column ){ return $column->isForeingkey (); } ); |
|
| 140 | + $this->foreingkeys = array_filter($this->columns, function($column) { return $column->isForeingkey(); } ); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | return $this->foreingkeys; |
@@ -147,11 +147,11 @@ discard block |
||
| 147 | 147 | /** |
| 148 | 148 | * @return \Classes\Db\Column[] |
| 149 | 149 | */ |
| 150 | - public function getDependences () |
|
| 150 | + public function getDependences() |
|
| 151 | 151 | { |
| 152 | - if ( empty ( $this->dependence ) ) |
|
| 152 | + if (empty ($this->dependence)) |
|
| 153 | 153 | { |
| 154 | - $this->dependence = array_filter ( $this->columns , function ( $column ){ return $column->hasDependence (); } ); |
|
| 154 | + $this->dependence = array_filter($this->columns, function($column) { return $column->hasDependence(); } ); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | return $this->dependence; |
@@ -160,11 +160,11 @@ discard block |
||
| 160 | 160 | /** |
| 161 | 161 | * @return string[] |
| 162 | 162 | */ |
| 163 | - public function getSequences () |
|
| 163 | + public function getSequences() |
|
| 164 | 164 | { |
| 165 | - if ( empty ( $this->sequence ) ) |
|
| 165 | + if (empty ($this->sequence)) |
|
| 166 | 166 | { |
| 167 | - $this->sequence = array_filter ( $this->columns , function ( $column ){ return $column->hasSequence (); } ); |
|
| 167 | + $this->sequence = array_filter($this->columns, function($column) { return $column->hasSequence(); } ); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | return $this->sequence; |
@@ -173,20 +173,20 @@ discard block |
||
| 173 | 173 | /** |
| 174 | 174 | * @return bool |
| 175 | 175 | */ |
| 176 | - public function hasSequences () |
|
| 176 | + public function hasSequences() |
|
| 177 | 177 | { |
| 178 | - if ( empty ( $this->sequence ) ) |
|
| 178 | + if (empty ($this->sequence)) |
|
| 179 | 179 | { |
| 180 | - $this->getSequences (); |
|
| 180 | + $this->getSequences(); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - return ! empty ( $this->sequence ); |
|
| 183 | + return ! empty ($this->sequence); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
| 187 | 187 | * @return \Classes\Db\Column[] |
| 188 | 188 | */ |
| 189 | - public function getColumns () |
|
| 189 | + public function getColumns() |
|
| 190 | 190 | { |
| 191 | 191 | return $this->columns; |
| 192 | 192 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | /** |
| 195 | 195 | * @return string |
| 196 | 196 | */ |
| 197 | - public function getName () |
|
| 197 | + public function getName() |
|
| 198 | 198 | { |
| 199 | 199 | return $this->name; |
| 200 | 200 | } |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | /** |
| 203 | 203 | * @return string |
| 204 | 204 | */ |
| 205 | - public function getSchema () |
|
| 205 | + public function getSchema() |
|
| 206 | 206 | { |
| 207 | 207 | return $this->schema; |
| 208 | 208 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | /** |
| 211 | 211 | * @return bool |
| 212 | 212 | */ |
| 213 | - public function hasSchema () |
|
| 213 | + public function hasSchema() |
|
| 214 | 214 | { |
| 215 | 215 | return (bool) $this->schema; |
| 216 | 216 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | /** |
| 219 | 219 | * @return string |
| 220 | 220 | */ |
| 221 | - public function getDatabase () |
|
| 221 | + public function getDatabase() |
|
| 222 | 222 | { |
| 223 | 223 | return $this->database; |
| 224 | 224 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | /** |
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | - public function getNamespace () |
|
| 229 | + public function getNamespace() |
|
| 230 | 230 | { |
| 231 | 231 | return $this->namespace; |
| 232 | 232 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | /** |
| 235 | 235 | * @param string $Namespace |
| 236 | 236 | */ |
| 237 | - public function setNamespace ( $namespace ) |
|
| 237 | + public function setNamespace($namespace) |
|
| 238 | 238 | { |
| 239 | 239 | $this->namespace = $namespace; |
| 240 | 240 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @author Pedro Alarcao <[email protected]> |
| 18 | 18 | */ |
| 19 | - public function __construct () |
|
| 19 | + public function __construct() |
|
| 20 | 20 | { |
| 21 | 21 | } |
| 22 | 22 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | /** |
| 69 | 69 | * @return string |
| 70 | 70 | */ |
| 71 | - public function getName () |
|
| 71 | + public function getName() |
|
| 72 | 72 | { |
| 73 | 73 | return $this->name; |
| 74 | 74 | } |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @param $array |
| 80 | 80 | */ |
| 81 | - public function populate ( $array ) |
|
| 81 | + public function populate($array) |
|
| 82 | 82 | { |
| 83 | - $this->name = $array[ 'name' ]; |
|
| 84 | - $this->type = $array[ 'type' ]; |
|
| 85 | - $this->nullable = $array[ 'nullable' ]; |
|
| 86 | - $this->max_length = $array[ 'max_length' ]; |
|
| 83 | + $this->name = $array['name']; |
|
| 84 | + $this->type = $array['type']; |
|
| 85 | + $this->nullable = $array['nullable']; |
|
| 86 | + $this->max_length = $array['max_length']; |
|
| 87 | 87 | |
| 88 | 88 | return $this; |
| 89 | 89 | } |
@@ -91,31 +91,31 @@ discard block |
||
| 91 | 91 | /** |
| 92 | 92 | * @return boolean |
| 93 | 93 | */ |
| 94 | - public function isPrimaryKey () |
|
| 94 | + public function isPrimaryKey() |
|
| 95 | 95 | { |
| 96 | - return ! empty( $this->primarykey ); |
|
| 96 | + return ! empty($this->primarykey); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * @return boolean |
| 101 | 101 | */ |
| 102 | - public function isForeingkey () |
|
| 102 | + public function isForeingkey() |
|
| 103 | 103 | { |
| 104 | - return ! empty( $this->refForeingkey ); |
|
| 104 | + return ! empty($this->refForeingkey); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * @return boolean |
| 109 | 109 | */ |
| 110 | - public function hasDependence () |
|
| 110 | + public function hasDependence() |
|
| 111 | 111 | { |
| 112 | - return ! empty( $this->dependences ); |
|
| 112 | + return ! empty($this->dependences); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | 116 | * @return string |
| 117 | 117 | */ |
| 118 | - public function getType () |
|
| 118 | + public function getType() |
|
| 119 | 119 | { |
| 120 | 120 | return $this->type; |
| 121 | 121 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | /** |
| 124 | 124 | * @return string |
| 125 | 125 | */ |
| 126 | - public function getComment () |
|
| 126 | + public function getComment() |
|
| 127 | 127 | { |
| 128 | 128 | return $this->comment; |
| 129 | 129 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | /** |
| 132 | 132 | * @param string $comment |
| 133 | 133 | */ |
| 134 | - public function setComment ( $comment ) |
|
| 134 | + public function setComment($comment) |
|
| 135 | 135 | { |
| 136 | 136 | $this->comment = $comment; |
| 137 | 137 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | /** |
| 142 | 142 | * @param \Classes\Db\Constrant $primarykey |
| 143 | 143 | */ |
| 144 | - public function setPrimaryKey ( Constrant $primarykey ) |
|
| 144 | + public function setPrimaryKey(Constrant $primarykey) |
|
| 145 | 145 | { |
| 146 | 146 | $this->primarykey = $primarykey; |
| 147 | 147 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | /** |
| 152 | 152 | * @param \Classes\Db\Constrant $dependece |
| 153 | 153 | */ |
| 154 | - public function addDependece ( Constrant $dependece ) |
|
| 154 | + public function addDependece(Constrant $dependece) |
|
| 155 | 155 | { |
| 156 | 156 | $this->dependences[] = $dependece; |
| 157 | 157 | |
@@ -165,19 +165,19 @@ discard block |
||
| 165 | 165 | * |
| 166 | 166 | * @return $this |
| 167 | 167 | */ |
| 168 | - public function createDependece ( $constraint_name , $table_name , $column_name , $schema = null ) |
|
| 168 | + public function createDependece($constraint_name, $table_name, $column_name, $schema = null) |
|
| 169 | 169 | { |
| 170 | 170 | $objConstrantDependence = new Constrant(); |
| 171 | - $objConstrantDependence->populate ( |
|
| 172 | - array ( |
|
| 173 | - 'constrant' => $constraint_name , |
|
| 174 | - 'schema' => $schema , |
|
| 175 | - 'table' => $table_name , |
|
| 171 | + $objConstrantDependence->populate( |
|
| 172 | + array( |
|
| 173 | + 'constrant' => $constraint_name, |
|
| 174 | + 'schema' => $schema, |
|
| 175 | + 'table' => $table_name, |
|
| 176 | 176 | 'column' => $column_name |
| 177 | 177 | ) |
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | - $this->addDependece ( $objConstrantDependence ); |
|
| 180 | + $this->addDependece($objConstrantDependence); |
|
| 181 | 181 | |
| 182 | 182 | return $this; |
| 183 | 183 | } |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | /** |
| 186 | 186 | * @param \Classes\Db\Constrant $reference |
| 187 | 187 | */ |
| 188 | - public function addRefFk ( Constrant $reference ) |
|
| 188 | + public function addRefFk(Constrant $reference) |
|
| 189 | 189 | { |
| 190 | 190 | $this->refForeingkey = $reference; |
| 191 | 191 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * |
| 198 | 198 | * @return \Classes\Db\Constrant |
| 199 | 199 | */ |
| 200 | - public function getFks () |
|
| 200 | + public function getFks() |
|
| 201 | 201 | { |
| 202 | 202 | return $this->refForeingkey; |
| 203 | 203 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @return \Classes\Db\Constrant[] |
| 209 | 209 | */ |
| 210 | - public function getDependences () |
|
| 210 | + public function getDependences() |
|
| 211 | 211 | { |
| 212 | 212 | return $this->dependences; |
| 213 | 213 | } |
@@ -215,9 +215,9 @@ discard block |
||
| 215 | 215 | /** |
| 216 | 216 | * @return bool |
| 217 | 217 | */ |
| 218 | - public function hasDependences () |
|
| 218 | + public function hasDependences() |
|
| 219 | 219 | { |
| 220 | - return (bool) count ( $this->dependences ); |
|
| 220 | + return (bool) count($this->dependences); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @return \Classes\Db\Constrant[] |
| 227 | 227 | */ |
| 228 | - public function getPrimaryKey () |
|
| 228 | + public function getPrimaryKey() |
|
| 229 | 229 | { |
| 230 | 230 | return $this->primarykey; |
| 231 | 231 | } |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | /** |
| 234 | 234 | * |
| 235 | 235 | */ |
| 236 | - public function getMaxLength () |
|
| 236 | + public function getMaxLength() |
|
| 237 | 237 | { |
| 238 | 238 | return $this->max_length; |
| 239 | 239 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | /** |
| 242 | 242 | * @return bool |
| 243 | 243 | */ |
| 244 | - public function hasSequence () |
|
| 244 | + public function hasSequence() |
|
| 245 | 245 | { |
| 246 | 246 | return (bool) $this->sequence; |
| 247 | 247 | } |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | /** |
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | - public function getSequence () |
|
| 252 | + public function getSequence() |
|
| 253 | 253 | { |
| 254 | 254 | return $this->sequence; |
| 255 | 255 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | /** |
| 258 | 258 | * @param string $sequence |
| 259 | 259 | */ |
| 260 | - public function setSequence ( $sequence ) |
|
| 260 | + public function setSequence($sequence) |
|
| 261 | 261 | { |
| 262 | 262 | $this->sequence = $sequence; |
| 263 | 263 | } |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | /** |
| 266 | 266 | * @return boolean |
| 267 | 267 | */ |
| 268 | - public function isNullable () |
|
| 268 | + public function isNullable() |
|
| 269 | 269 | { |
| 270 | 270 | return $this->nullable; |
| 271 | 271 | } |