@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | /** |
| 59 | 59 | * @type \Classes\Db\DbTable[][] |
| 60 | 60 | */ |
| 61 | - private $objDbTables = array (); |
|
| 61 | + private $objDbTables = array(); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * @var AbstractAdapter |
@@ -73,22 +73,22 @@ discard block |
||
| 73 | 73 | /** |
| 74 | 74 | * analisa e popula as Foreing keys, Primary keys e dependencias do banco nos objetos |
| 75 | 75 | */ |
| 76 | - protected function parseConstrants () |
|
| 76 | + protected function parseConstrants() |
|
| 77 | 77 | { |
| 78 | - foreach ( $this->getListConstrant () as $constrant ) |
|
| 78 | + foreach ($this->getListConstrant() as $constrant) |
|
| 79 | 79 | { |
| 80 | 80 | |
| 81 | - $schema = $constrant[ 'table_schema' ]; |
|
| 82 | - $table_name = $constrant [ 'table_name' ]; |
|
| 83 | - $this->populateForeignAndPrimaryKeys ( $constrant , $table_name , $schema ); |
|
| 84 | - unset( $table_name , $schema ); |
|
| 81 | + $schema = $constrant['table_schema']; |
|
| 82 | + $table_name = $constrant ['table_name']; |
|
| 83 | + $this->populateForeignAndPrimaryKeys($constrant, $table_name, $schema); |
|
| 84 | + unset($table_name, $schema); |
|
| 85 | 85 | |
| 86 | - if ( $constrant[ 'constraint_type' ] == "FOREIGN KEY" ) |
|
| 86 | + if ($constrant['constraint_type'] == "FOREIGN KEY") |
|
| 87 | 87 | { |
| 88 | - $schema = $constrant[ 'foreign_schema' ]; |
|
| 89 | - $table_name = $constrant [ 'foreign_table' ]; |
|
| 90 | - $this->populateDependece ( $constrant , $table_name , $schema ); |
|
| 91 | - unset( $table_name , $schema ); |
|
| 88 | + $schema = $constrant['foreign_schema']; |
|
| 89 | + $table_name = $constrant ['foreign_table']; |
|
| 90 | + $this->populateDependece($constrant, $table_name, $schema); |
|
| 91 | + unset($table_name, $schema); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -98,36 +98,36 @@ discard block |
||
| 98 | 98 | * @param string $table_name |
| 99 | 99 | * @param int $schema |
| 100 | 100 | */ |
| 101 | - private function populateForeignAndPrimaryKeys ( $constrant , $table_name , $schema = 0 ) |
|
| 101 | + private function populateForeignAndPrimaryKeys($constrant, $table_name, $schema = 0) |
|
| 102 | 102 | { |
| 103 | - if ( $this->hasTable ( $table_name , $schema ) ) |
|
| 103 | + if ($this->hasTable($table_name, $schema)) |
|
| 104 | 104 | { |
| 105 | - $table = $this->getTable ( $table_name , $schema ); |
|
| 106 | - if ( $table->hasColumn ( $constrant[ "column_name" ] ) ) |
|
| 105 | + $table = $this->getTable($table_name, $schema); |
|
| 106 | + if ($table->hasColumn($constrant["column_name"])) |
|
| 107 | 107 | { |
| 108 | - $objConstrant = Constrant::getInstance () |
|
| 109 | - ->populate ( |
|
| 110 | - array ( |
|
| 111 | - 'constrant' => $constrant[ 'constraint_name' ] , |
|
| 112 | - 'schema' => $constrant[ 'foreign_schema' ] , |
|
| 113 | - 'table' => $constrant[ 'foreign_table' ] , |
|
| 114 | - 'column' => $constrant[ 'foreign_column' ] |
|
| 108 | + $objConstrant = Constrant::getInstance() |
|
| 109 | + ->populate( |
|
| 110 | + array( |
|
| 111 | + 'constrant' => $constrant['constraint_name'], |
|
| 112 | + 'schema' => $constrant['foreign_schema'], |
|
| 113 | + 'table' => $constrant['foreign_table'], |
|
| 114 | + 'column' => $constrant['foreign_column'] |
|
| 115 | 115 | ) |
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | - switch ( $constrant[ 'constraint_type' ] ) |
|
| 118 | + switch ($constrant['constraint_type']) |
|
| 119 | 119 | { |
| 120 | 120 | case "FOREIGN KEY": |
| 121 | - $table->getColumn ( $constrant[ "column_name" ] ) |
|
| 122 | - ->addRefFk ( $objConstrant ); |
|
| 121 | + $table->getColumn($constrant["column_name"]) |
|
| 122 | + ->addRefFk($objConstrant); |
|
| 123 | 123 | break; |
| 124 | 124 | case"PRIMARY KEY": |
| 125 | - $table->getColumn ( $constrant[ "column_name" ] ) |
|
| 126 | - ->setPrimaryKey ( $objConstrant ) |
|
| 127 | - ->setSequence ( |
|
| 128 | - $this->getSequence ( |
|
| 129 | - $schema . '.' . $table_name , |
|
| 130 | - $constrant[ "column_name" ] |
|
| 125 | + $table->getColumn($constrant["column_name"]) |
|
| 126 | + ->setPrimaryKey($objConstrant) |
|
| 127 | + ->setSequence( |
|
| 128 | + $this->getSequence( |
|
| 129 | + $schema . '.' . $table_name, |
|
| 130 | + $constrant["column_name"] |
|
| 131 | 131 | ) |
| 132 | 132 | ); |
| 133 | 133 | break; |
@@ -141,19 +141,19 @@ discard block |
||
| 141 | 141 | * @param string $table_name |
| 142 | 142 | * @param int $schema |
| 143 | 143 | */ |
| 144 | - private function populateDependece ( $constrant , $table_name , $schema = 0 ) |
|
| 144 | + private function populateDependece($constrant, $table_name, $schema = 0) |
|
| 145 | 145 | { |
| 146 | - if ( $this->hasTable ( $table_name , $schema ) ) |
|
| 146 | + if ($this->hasTable($table_name, $schema)) |
|
| 147 | 147 | { |
| 148 | - $table = $this->getTable ( $table_name , $schema ); |
|
| 149 | - if ( $table->hasColumn ( $constrant[ "foreign_column" ] ) ) |
|
| 148 | + $table = $this->getTable($table_name, $schema); |
|
| 149 | + if ($table->hasColumn($constrant["foreign_column"])) |
|
| 150 | 150 | { |
| 151 | - $table->getColumn ( $constrant[ "foreign_column" ] ) |
|
| 152 | - ->createDependece ( |
|
| 153 | - $constrant[ 'constraint_name' ] , |
|
| 154 | - $constrant[ 'table_name' ] , |
|
| 155 | - $constrant[ 'column_name' ] , |
|
| 156 | - $constrant[ 'table_schema' ] |
|
| 151 | + $table->getColumn($constrant["foreign_column"]) |
|
| 152 | + ->createDependece( |
|
| 153 | + $constrant['constraint_name'], |
|
| 154 | + $constrant['table_name'], |
|
| 155 | + $constrant['column_name'], |
|
| 156 | + $constrant['table_schema'] |
|
| 157 | 157 | ); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -162,14 +162,14 @@ discard block |
||
| 162 | 162 | /** |
| 163 | 163 | * cria um Array com nome das tabelas |
| 164 | 164 | */ |
| 165 | - abstract protected function parseTables (); |
|
| 165 | + abstract protected function parseTables(); |
|
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * retorna o numero total de tabelas |
| 169 | 169 | * |
| 170 | 170 | * @return int |
| 171 | 171 | */ |
| 172 | - abstract public function getTotalTables (); |
|
| 172 | + abstract public function getTotalTables(); |
|
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | 175 | * Retorna o Nome da Sequence da tabela |
@@ -179,23 +179,23 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @return string |
| 181 | 181 | */ |
| 182 | - abstract public function getSequence ( $table , $column ); |
|
| 182 | + abstract public function getSequence($table, $column); |
|
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * @return array |
| 186 | 186 | */ |
| 187 | - abstract public function getListConstrant (); |
|
| 187 | + abstract public function getListConstrant(); |
|
| 188 | 188 | |
| 189 | 189 | /** |
| 190 | 190 | * @param string $str |
| 191 | 191 | * |
| 192 | 192 | * @return string |
| 193 | 193 | */ |
| 194 | - protected function convertTypeToPhp ( $str ) |
|
| 194 | + protected function convertTypeToPhp($str) |
|
| 195 | 195 | { |
| 196 | - if ( isset( $this->dataTypes[ $str ] ) ) |
|
| 196 | + if (isset($this->dataTypes[$str])) |
|
| 197 | 197 | { |
| 198 | - return $this->dataTypes[ $str ]; |
|
| 198 | + return $this->dataTypes[$str]; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | return 'string'; |
@@ -204,12 +204,12 @@ discard block |
||
| 204 | 204 | /** |
| 205 | 205 | * @return string |
| 206 | 206 | */ |
| 207 | - abstract public function getPDOString (); |
|
| 207 | + abstract public function getPDOString(); |
|
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | - abstract public function getPDOSocketString (); |
|
| 212 | + abstract public function getPDOSocketString(); |
|
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | 215 | * @param $nameTable |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return \Classes\Db\DbTable |
| 219 | 219 | */ |
| 220 | - public function createTable ( $nameTable , $schema = 0 ) |
|
| 220 | + public function createTable($nameTable, $schema = 0) |
|
| 221 | 221 | { |
| 222 | - $this->objDbTables[ $schema ][ trim ( $nameTable ) ] = DbTable::getInstance () |
|
| 223 | - ->populate ( |
|
| 224 | - array ( |
|
| 225 | - 'table' => $nameTable , |
|
| 226 | - 'schema' => $schema , |
|
| 222 | + $this->objDbTables[$schema][trim($nameTable)] = DbTable::getInstance() |
|
| 223 | + ->populate( |
|
| 224 | + array( |
|
| 225 | + 'table' => $nameTable, |
|
| 226 | + 'schema' => $schema, |
|
| 227 | 227 | 'database' => $this->database |
| 228 | 228 | ) |
| 229 | 229 | ); |
@@ -236,24 +236,24 @@ discard block |
||
| 236 | 236 | * |
| 237 | 237 | * @return \Classes\Db\DbTable[] |
| 238 | 238 | */ |
| 239 | - public function getTables ( $schema = 0 ) |
|
| 239 | + public function getTables($schema = 0) |
|
| 240 | 240 | { |
| 241 | - if ( ! isset( $this->objDbTables[ $schema ] ) ) |
|
| 241 | + if ( ! isset($this->objDbTables[$schema])) |
|
| 242 | 242 | { |
| 243 | - return array (); |
|
| 243 | + return array(); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - return $this->objDbTables[ $schema ]; |
|
| 246 | + return $this->objDbTables[$schema]; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - public function getAllTables () |
|
| 249 | + public function getAllTables() |
|
| 250 | 250 | { |
| 251 | 251 | return $this->objDbTables; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - public function hasTables () |
|
| 254 | + public function hasTables() |
|
| 255 | 255 | { |
| 256 | - return ! empty( $this->objDbTables ); |
|
| 256 | + return ! empty($this->objDbTables); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -263,9 +263,9 @@ discard block |
||
| 263 | 263 | * |
| 264 | 264 | * @return \Classes\Db\DbTable |
| 265 | 265 | */ |
| 266 | - public function getTable ( $nameTable , $schema = 0 ) |
|
| 266 | + public function getTable($nameTable, $schema = 0) |
|
| 267 | 267 | { |
| 268 | - return $this->objDbTables[ $schema ][ trim ( $nameTable ) ]; |
|
| 268 | + return $this->objDbTables[$schema][trim($nameTable)]; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -274,9 +274,9 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @return bool |
| 276 | 276 | */ |
| 277 | - public function hasTable ( $nameTable , $schema = 0 ) |
|
| 277 | + public function hasTable($nameTable, $schema = 0) |
|
| 278 | 278 | { |
| 279 | - return isset( $this->objDbTables[ $schema ][ trim ( $nameTable ) ] ); |
|
| 279 | + return isset($this->objDbTables[$schema][trim($nameTable)]); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -284,64 +284,64 @@ discard block |
||
| 284 | 284 | * |
| 285 | 285 | * @return array[] |
| 286 | 286 | */ |
| 287 | - abstract public function getListColumns (); |
|
| 287 | + abstract public function getListColumns(); |
|
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | 290 | * Retorna um Array com nome das tabelas |
| 291 | 291 | * |
| 292 | 292 | * @return string[] |
| 293 | 293 | */ |
| 294 | - abstract public function getListNameTable (); |
|
| 294 | + abstract public function getListNameTable(); |
|
| 295 | 295 | |
| 296 | 296 | /** |
| 297 | 297 | * @param \Classes\AdapterConfig\AbstractAdapter $adapterConfig |
| 298 | 298 | */ |
| 299 | - public function __construct ( AbstractAdapter $adapterConfig ) |
|
| 299 | + public function __construct(AbstractAdapter $adapterConfig) |
|
| 300 | 300 | { |
| 301 | 301 | $this->config = $adapterConfig; |
| 302 | - $this->host = $adapterConfig->getHost (); |
|
| 303 | - $this->database = $adapterConfig->getDatabase (); |
|
| 304 | - $this->port = $adapterConfig->hasPort () ? $adapterConfig->getPort () |
|
| 302 | + $this->host = $adapterConfig->getHost(); |
|
| 303 | + $this->database = $adapterConfig->getDatabase(); |
|
| 304 | + $this->port = $adapterConfig->hasPort() ? $adapterConfig->getPort() |
|
| 305 | 305 | : $this->port; |
| 306 | - $this->username = $adapterConfig->getUser (); |
|
| 307 | - $this->password = $adapterConfig->getPassword (); |
|
| 308 | - $this->socket = $adapterConfig->getSocket (); |
|
| 306 | + $this->username = $adapterConfig->getUser(); |
|
| 307 | + $this->password = $adapterConfig->getPassword(); |
|
| 308 | + $this->socket = $adapterConfig->getSocket(); |
|
| 309 | 309 | |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
| 313 | 313 | * Executa as consultas do banco de dados |
| 314 | 314 | */ |
| 315 | - public function runDatabase () |
|
| 315 | + public function runDatabase() |
|
| 316 | 316 | { |
| 317 | - $this->parseTables (); |
|
| 318 | - $this->parseConstrants (); |
|
| 317 | + $this->parseTables(); |
|
| 318 | + $this->parseConstrants(); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
| 322 | 322 | * |
| 323 | 323 | * @return \PDO |
| 324 | 324 | */ |
| 325 | - public function getPDO () |
|
| 325 | + public function getPDO() |
|
| 326 | 326 | { |
| 327 | - if ( is_null ( $this->_pdo ) ) |
|
| 327 | + if (is_null($this->_pdo)) |
|
| 328 | 328 | { |
| 329 | - if ( ! empty( $this->socket ) ) |
|
| 329 | + if ( ! empty($this->socket)) |
|
| 330 | 330 | { |
| 331 | - $pdoString = $this->getPDOSocketString (); |
|
| 331 | + $pdoString = $this->getPDOSocketString(); |
|
| 332 | 332 | } else |
| 333 | 333 | { |
| 334 | - $pdoString = $this->getPDOString (); |
|
| 334 | + $pdoString = $this->getPDOString(); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | try |
| 338 | 338 | { |
| 339 | - $this->_pdo = new \PDO ( |
|
| 340 | - $pdoString , $this->username , $this->password |
|
| 339 | + $this->_pdo = new \PDO( |
|
| 340 | + $pdoString, $this->username, $this->password |
|
| 341 | 341 | ); |
| 342 | - } catch ( \Exception $e ) |
|
| 342 | + } catch (\Exception $e) |
|
| 343 | 343 | { |
| 344 | - die ( "pdo error: " . $e->getMessage () . "\n" ); |
|
| 344 | + die ("pdo error: " . $e->getMessage() . "\n"); |
|
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | 347 | |