@@ -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 | - protected abstract function parseTables (); |
|
| 165 | + protected abstract function parseTables(); |
|
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * retorna o numero total de tabelas |
| 169 | 169 | * |
| 170 | 170 | * @return int |
| 171 | 171 | */ |
| 172 | - public abstract function getTotalTables (); |
|
| 172 | + public abstract 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 | - public abstract function getSequence ( $table , $column ); |
|
| 182 | + public abstract function getSequence($table, $column); |
|
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * @return array |
| 186 | 186 | */ |
| 187 | - public abstract function getListConstrant (); |
|
| 187 | + public abstract 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 | - public abstract function getPDOString (); |
|
| 207 | + public abstract function getPDOString(); |
|
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | - public abstract function getPDOSocketString (); |
|
| 212 | + public abstract 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 | - public abstract function getListColumns (); |
|
| 287 | + public abstract function getListColumns(); |
|
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | 290 | * Retorna um Array com nome das tabelas |
| 291 | 291 | * |
| 292 | 292 | * @return string[] |
| 293 | 293 | */ |
| 294 | - public abstract function getListNameTable (); |
|
| 294 | + public abstract 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 | |
@@ -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, |
| 86 | 86 | table_name |
| 87 | 87 | FROM information_schema.tables |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | table_schema, |
| 93 | 93 | table_name |
| 94 | 94 | ASC" |
| 95 | - )->fetchAll (); |
|
| 95 | + )->fetchAll(); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | return $this->tableList; |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return array |
| 105 | 105 | */ |
| 106 | - public function getListColumns () |
|
| 106 | + public function getListColumns() |
|
| 107 | 107 | { |
| 108 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 108 | + $strSchema = implode("', '", $this->schema); |
|
| 109 | 109 | |
| 110 | - return $this->getPDO ()->query ( |
|
| 110 | + return $this->getPDO()->query( |
|
| 111 | 111 | "SELECT distinct |
| 112 | 112 | c.table_schema, |
| 113 | 113 | c.table_name, |
@@ -121,14 +121,14 @@ discard block |
||
| 121 | 121 | ON st.table_name=c.table_name and st.table_type = 'BASE TABLE' |
| 122 | 122 | and c.table_schema IN ('$strSchema') |
| 123 | 123 | order by c.table_name asc" |
| 124 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 124 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - public function getListConstrant () |
|
| 127 | + public function getListConstrant() |
|
| 128 | 128 | { |
| 129 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 129 | + $strSchema = implode("', '", $this->schema); |
|
| 130 | 130 | |
| 131 | - return $this->getPDO ()->query ( |
|
| 131 | + return $this->getPDO()->query( |
|
| 132 | 132 | "SELECT distinct |
| 133 | 133 | tc.constraint_type, |
| 134 | 134 | tc.constraint_name, |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | ON tc.constraint_name = ccu.constraint_name |
| 149 | 149 | AND tc.constraint_schema = ccu.constraint_schema |
| 150 | 150 | ORDER by tc.table_schema" |
| 151 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 151 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | |
@@ -160,20 +160,20 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return string |
| 162 | 162 | */ |
| 163 | - public function getSequence ( $table , $column ) |
|
| 163 | + public function getSequence($table, $column) |
|
| 164 | 164 | { |
| 165 | - $pdo = $this->getPDO (); |
|
| 166 | - $return1 = $pdo->query ( "SELECT pg_get_serial_sequence('$table', '$column');" ) |
|
| 167 | - ->fetchColumn (); |
|
| 165 | + $pdo = $this->getPDO(); |
|
| 166 | + $return1 = $pdo->query("SELECT pg_get_serial_sequence('$table', '$column');") |
|
| 167 | + ->fetchColumn(); |
|
| 168 | 168 | |
| 169 | - if ( $return1 ) |
|
| 169 | + if ($return1) |
|
| 170 | 170 | { |
| 171 | 171 | return $return1; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - $dtbase = explode ( '.' , $table );; |
|
| 174 | + $dtbase = explode('.', $table); ; |
|
| 175 | 175 | |
| 176 | - $stmt = $pdo->prepare ( |
|
| 176 | + $stmt = $pdo->prepare( |
|
| 177 | 177 | "SELECT adsrc FROM pg_attrdef AS att |
| 178 | 178 | INNER JOIN pg_class AS c |
| 179 | 179 | ON adrelid = c.oid AND att.adnum=1 AND c.relname = ? |
@@ -181,19 +181,19 @@ discard block |
||
| 181 | 181 | ON n.oid = c.relnamespace and n.nspname=?" |
| 182 | 182 | ); |
| 183 | 183 | |
| 184 | - $schema = isset( $dtbase[ 1 ] ) ? $dtbase[ 1 ] : 'public'; |
|
| 184 | + $schema = isset($dtbase[1]) ? $dtbase[1] : 'public'; |
|
| 185 | 185 | |
| 186 | - $stmt->bindParam ( 1 , $schema ); |
|
| 187 | - $stmt->bindParam ( 2 , $dtbase[ 0 ] ); |
|
| 188 | - $stmt->execute (); |
|
| 189 | - $return2 = $stmt->fetchColumn (); |
|
| 190 | - if ( $return2 ) |
|
| 186 | + $stmt->bindParam(1, $schema); |
|
| 187 | + $stmt->bindParam(2, $dtbase[0]); |
|
| 188 | + $stmt->execute(); |
|
| 189 | + $return2 = $stmt->fetchColumn(); |
|
| 190 | + if ($return2) |
|
| 191 | 191 | { |
| 192 | - return preg_filter ( |
|
| 193 | - array ( |
|
| 194 | - '/nextval\(\'/' , |
|
| 192 | + return preg_filter( |
|
| 193 | + array( |
|
| 194 | + '/nextval\(\'/', |
|
| 195 | 195 | '/\'::regclass\)/' |
| 196 | - ) , '' , $return2 |
|
| 196 | + ), '', $return2 |
|
| 197 | 197 | ); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -202,36 +202,36 @@ discard block |
||
| 202 | 202 | /** |
| 203 | 203 | * @inheritDoc |
| 204 | 204 | */ |
| 205 | - public function parseTables () |
|
| 205 | + public function parseTables() |
|
| 206 | 206 | { |
| 207 | - if ( $this->hasTables () ) |
|
| 207 | + if ($this->hasTables()) |
|
| 208 | 208 | { |
| 209 | - return $this->getAllTables (); |
|
| 209 | + return $this->getAllTables(); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - foreach ( $this->getListColumns () as $table ) |
|
| 212 | + foreach ($this->getListColumns() as $table) |
|
| 213 | 213 | { |
| 214 | - $schema = $table[ 'table_schema' ]; |
|
| 215 | - $key = $table [ 'table_name' ]; |
|
| 216 | - if ( ! $this->hasTable ( $key , $schema ) ) |
|
| 214 | + $schema = $table['table_schema']; |
|
| 215 | + $key = $table ['table_name']; |
|
| 216 | + if ( ! $this->hasTable($key, $schema)) |
|
| 217 | 217 | { |
| 218 | - $this->createTable ( $key , $schema ); |
|
| 218 | + $this->createTable($key, $schema); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $column = Column::getInstance () |
|
| 222 | - ->populate ( |
|
| 223 | - array ( |
|
| 224 | - 'name' => $table [ 'column_name' ] , |
|
| 225 | - 'type' => $this->convertTypeToPhp ( $table[ 'data_type' ] ) , |
|
| 226 | - 'nullable' => ( $table[ 'is_nullable' ] == 'YES' ) , |
|
| 227 | - 'max_length' => $table[ 'max_length' ] |
|
| 221 | + $column = Column::getInstance() |
|
| 222 | + ->populate( |
|
| 223 | + array( |
|
| 224 | + 'name' => $table ['column_name'], |
|
| 225 | + 'type' => $this->convertTypeToPhp($table['data_type']), |
|
| 226 | + 'nullable' => ($table['is_nullable'] == 'YES'), |
|
| 227 | + 'max_length' => $table['max_length'] |
|
| 228 | 228 | ) |
| 229 | 229 | ); |
| 230 | 230 | |
| 231 | - $this->getTable ( $key , $schema ) |
|
| 232 | - ->addColumn ( $column ) |
|
| 233 | - ->setNamespace ( |
|
| 234 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 231 | + $this->getTable($key, $schema) |
|
| 232 | + ->addColumn($column) |
|
| 233 | + ->setNamespace( |
|
| 234 | + $this->config->createClassNamespace($this->getTable($key, $schema)) |
|
| 235 | 235 | ); |
| 236 | 236 | } |
| 237 | 237 | } |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | * @inheritDoc |
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | - public function getPDOString () |
|
| 243 | + public function getPDOString() |
|
| 244 | 244 | { |
| 245 | - return sprintf ( |
|
| 246 | - "pgsql:host=%s;port=%s;dbname=%s" , |
|
| 247 | - $this->host , |
|
| 248 | - $this->port , |
|
| 245 | + return sprintf( |
|
| 246 | + "pgsql:host=%s;port=%s;dbname=%s", |
|
| 247 | + $this->host, |
|
| 248 | + $this->port, |
|
| 249 | 249 | $this->database |
| 250 | 250 | |
| 251 | 251 | ); |
@@ -255,11 +255,11 @@ discard block |
||
| 255 | 255 | * @inheritDoc |
| 256 | 256 | * @return string |
| 257 | 257 | */ |
| 258 | - public function getPDOSocketString () |
|
| 258 | + public function getPDOSocketString() |
|
| 259 | 259 | { |
| 260 | - return sprintf ( |
|
| 261 | - "pgsql:unix_socket=%s;dbname=%s" , |
|
| 262 | - $this->socket , |
|
| 260 | + return sprintf( |
|
| 261 | + "pgsql:unix_socket=%s;dbname=%s", |
|
| 262 | + $this->socket, |
|
| 263 | 263 | $this->database |
| 264 | 264 | |
| 265 | 265 | ); |
@@ -270,19 +270,19 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return int |
| 272 | 272 | */ |
| 273 | - public function getTotalTables () |
|
| 273 | + public function getTotalTables() |
|
| 274 | 274 | { |
| 275 | - if ( empty( $this->totalTables ) ) |
|
| 275 | + if (empty($this->totalTables)) |
|
| 276 | 276 | { |
| 277 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 277 | + $strSchema = implode("', '", $this->schema); |
|
| 278 | 278 | |
| 279 | - $this->totalTables = $this->getPDO ()->query ( |
|
| 279 | + $this->totalTables = $this->getPDO()->query( |
|
| 280 | 280 | "SELECT COUNT(table_name) AS total |
| 281 | 281 | FROM information_schema.tables |
| 282 | 282 | WHERE |
| 283 | 283 | table_type = 'BASE TABLE' |
| 284 | 284 | AND table_schema IN ( '" . $strSchema . "' )" |
| 285 | - )->fetchColumn (); |
|
| 285 | + )->fetchColumn(); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | 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,36 +55,36 @@ discard block |
||
| 55 | 55 | /** |
| 56 | 56 | * @inheritDoc |
| 57 | 57 | */ |
| 58 | - public function parseTables () |
|
| 58 | + public function parseTables() |
|
| 59 | 59 | { |
| 60 | - if ( $this->hasTables () ) |
|
| 60 | + if ($this->hasTables()) |
|
| 61 | 61 | { |
| 62 | - return $this->getAllTables (); |
|
| 62 | + return $this->getAllTables(); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $schema = 0; |
| 66 | - foreach ( $this->getListColumns () as $table ) |
|
| 66 | + foreach ($this->getListColumns() as $table) |
|
| 67 | 67 | { |
| 68 | - $key = $table [ 'table_name' ]; |
|
| 69 | - if ( ! $this->hasTable ( $key , $schema ) ) |
|
| 68 | + $key = $table ['table_name']; |
|
| 69 | + if ( ! $this->hasTable($key, $schema)) |
|
| 70 | 70 | { |
| 71 | - $this->createTable ( $key , $schema ); |
|
| 71 | + $this->createTable($key, $schema); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $column = Column::getInstance () |
|
| 75 | - ->populate ( |
|
| 76 | - array ( |
|
| 77 | - 'name' => $table [ 'column_name' ] , |
|
| 78 | - 'type' => $this->convertTypeToPhp ( $table[ 'data_type' ] ) , |
|
| 79 | - 'nullable' => ( $table[ 'is_nullable' ] == 'YES' ) , |
|
| 80 | - 'max_length' => $table[ 'max_length' ] |
|
| 74 | + $column = Column::getInstance() |
|
| 75 | + ->populate( |
|
| 76 | + array( |
|
| 77 | + 'name' => $table ['column_name'], |
|
| 78 | + 'type' => $this->convertTypeToPhp($table['data_type']), |
|
| 79 | + 'nullable' => ($table['is_nullable'] == 'YES'), |
|
| 80 | + 'max_length' => $table['max_length'] |
|
| 81 | 81 | ) |
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | - $this->getTable ( $key , $schema ) |
|
| 85 | - ->addColumn ( $column ) |
|
| 86 | - ->setNamespace ( |
|
| 87 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 84 | + $this->getTable($key, $schema) |
|
| 85 | + ->addColumn($column) |
|
| 86 | + ->setNamespace( |
|
| 87 | + $this->config->createClassNamespace($this->getTable($key, $schema)) |
|
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -93,12 +93,12 @@ discard block |
||
| 93 | 93 | * @inheritDoc |
| 94 | 94 | * @return string |
| 95 | 95 | */ |
| 96 | - public function getPDOString () |
|
| 96 | + public function getPDOString() |
|
| 97 | 97 | { |
| 98 | - return sprintf ( |
|
| 99 | - "mysql:host=%s;port=%s;dbname=%s" , |
|
| 100 | - $this->host , |
|
| 101 | - $this->port , |
|
| 98 | + return sprintf( |
|
| 99 | + "mysql:host=%s;port=%s;dbname=%s", |
|
| 100 | + $this->host, |
|
| 101 | + $this->port, |
|
| 102 | 102 | $this->database |
| 103 | 103 | |
| 104 | 104 | ); |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | * @inheritDoc |
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | - public function getPDOSocketString () |
|
| 111 | + public function getPDOSocketString() |
|
| 112 | 112 | { |
| 113 | - return sprintf ( |
|
| 114 | - "mysql:unix_socket=%s;dbname=%s" , |
|
| 115 | - $this->socket , |
|
| 113 | + return sprintf( |
|
| 114 | + "mysql:unix_socket=%s;dbname=%s", |
|
| 115 | + $this->socket, |
|
| 116 | 116 | $this->database |
| 117 | 117 | |
| 118 | 118 | ); |
@@ -122,13 +122,13 @@ discard block |
||
| 122 | 122 | * @inheritDoc |
| 123 | 123 | * @return string[] |
| 124 | 124 | */ |
| 125 | - public function getListNameTable () |
|
| 125 | + public function getListNameTable() |
|
| 126 | 126 | { |
| 127 | - if ( empty( $this->tableList ) ) |
|
| 127 | + if (empty($this->tableList)) |
|
| 128 | 128 | { |
| 129 | - $this->tableList = $this->getPDO ()->query ( |
|
| 129 | + $this->tableList = $this->getPDO()->query( |
|
| 130 | 130 | "show tables" |
| 131 | - )->fetchAll (); |
|
| 131 | + )->fetchAll(); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | return $this->tableList; |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return array[] |
| 141 | 141 | */ |
| 142 | - public function getListColumns () |
|
| 142 | + public function getListColumns() |
|
| 143 | 143 | { |
| 144 | 144 | |
| 145 | - return $this->getPDO ()->query ( |
|
| 145 | + return $this->getPDO()->query( |
|
| 146 | 146 | "select |
| 147 | 147 | 0 AS table_schema, |
| 148 | 148 | table_name, |
@@ -153,15 +153,15 @@ discard block |
||
| 153 | 153 | from information_schema.columns |
| 154 | 154 | where table_schema IN ('{$this->database}') |
| 155 | 155 | order by table_name,ordinal_position" |
| 156 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 156 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | * @return array |
| 161 | 161 | */ |
| 162 | - public function getListConstrant () |
|
| 162 | + public function getListConstrant() |
|
| 163 | 163 | { |
| 164 | - return $this->getPDO ()->query ( |
|
| 164 | + return $this->getPDO()->query( |
|
| 165 | 165 | "SELECT distinct |
| 166 | 166 | i.constraint_type, |
| 167 | 167 | k.constraint_name, |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | WHERE |
| 179 | 179 | i.TABLE_SCHEMA IN ('{$this->database}') AND i.CONSTRAINT_TYPE IN ('FOREIGN KEY', 'PRIMARY KEY' ) |
| 180 | 180 | order by k.table_schema, k.table_name;" |
| 181 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 181 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -186,14 +186,14 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | * @return int |
| 188 | 188 | */ |
| 189 | - public function getTotalTables () |
|
| 189 | + public function getTotalTables() |
|
| 190 | 190 | { |
| 191 | - if ( empty( $this->totalTables ) ) |
|
| 191 | + if (empty($this->totalTables)) |
|
| 192 | 192 | { |
| 193 | 193 | |
| 194 | - $this->totalTables = $this->getPDO ()->query ( |
|
| 194 | + $this->totalTables = $this->getPDO()->query( |
|
| 195 | 195 | "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '{$this->database}'" |
| 196 | - )->fetchColumn (); |
|
| 196 | + )->fetchColumn(); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | return (int) $this->totalTables; |
@@ -205,13 +205,13 @@ discard block |
||
| 205 | 205 | * @param $table |
| 206 | 206 | * @param $column |
| 207 | 207 | */ |
| 208 | - public function getSequence ( $table , $column ) |
|
| 208 | + public function getSequence($table, $column) |
|
| 209 | 209 | { |
| 210 | - $return = $this->getPDO () |
|
| 211 | - ->query ( "select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';" ) |
|
| 212 | - ->fetch ( \PDO::FETCH_ASSOC ); |
|
| 210 | + $return = $this->getPDO() |
|
| 211 | + ->query("select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';") |
|
| 212 | + ->fetch(\PDO::FETCH_ASSOC); |
|
| 213 | 213 | |
| 214 | - if ( ! $return ) |
|
| 214 | + if ( ! $return) |
|
| 215 | 215 | { |
| 216 | 216 | return; |
| 217 | 217 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @author Pedro Alarcao <[email protected]> |
| 18 | 18 | */ |
| 19 | - final private function __construct () |
|
| 19 | + final private function __construct() |
|
| 20 | 20 | { |
| 21 | 21 | } |
| 22 | 22 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @return \Classes\Db\Column |
| 27 | 27 | */ |
| 28 | - public static function getInstance () |
|
| 28 | + public static function getInstance() |
|
| 29 | 29 | { |
| 30 | 30 | return new Column(); |
| 31 | 31 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | /** |
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | - public function getName () |
|
| 81 | + public function getName() |
|
| 82 | 82 | { |
| 83 | 83 | return $this->name; |
| 84 | 84 | } |
@@ -88,12 +88,12 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @param $array |
| 90 | 90 | */ |
| 91 | - public function populate ( $array ) |
|
| 91 | + public function populate($array) |
|
| 92 | 92 | { |
| 93 | - $this->name = $array[ 'name' ]; |
|
| 94 | - $this->type = $array[ 'type' ]; |
|
| 95 | - $this->nullable = $array[ 'nullable' ]; |
|
| 96 | - $this->max_length = $array[ 'max_length' ]; |
|
| 93 | + $this->name = $array['name']; |
|
| 94 | + $this->type = $array['type']; |
|
| 95 | + $this->nullable = $array['nullable']; |
|
| 96 | + $this->max_length = $array['max_length']; |
|
| 97 | 97 | |
| 98 | 98 | return $this; |
| 99 | 99 | } |
@@ -101,31 +101,31 @@ discard block |
||
| 101 | 101 | /** |
| 102 | 102 | * @return boolean |
| 103 | 103 | */ |
| 104 | - public function isPrimaryKey () |
|
| 104 | + public function isPrimaryKey() |
|
| 105 | 105 | { |
| 106 | - return ! empty( $this->primarykey ); |
|
| 106 | + return ! empty($this->primarykey); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * @return boolean |
| 111 | 111 | */ |
| 112 | - public function isForeingkey () |
|
| 112 | + public function isForeingkey() |
|
| 113 | 113 | { |
| 114 | - return ! empty( $this->refForeingkey ); |
|
| 114 | + return ! empty($this->refForeingkey); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * @return boolean |
| 119 | 119 | */ |
| 120 | - public function hasDependence () |
|
| 120 | + public function hasDependence() |
|
| 121 | 121 | { |
| 122 | - return ! empty( $this->dependences ); |
|
| 122 | + return ! empty($this->dependences); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | - public function getType () |
|
| 128 | + public function getType() |
|
| 129 | 129 | { |
| 130 | 130 | return $this->type; |
| 131 | 131 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | /** |
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | - public function getComment () |
|
| 136 | + public function getComment() |
|
| 137 | 137 | { |
| 138 | 138 | return $this->comment; |
| 139 | 139 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | /** |
| 142 | 142 | * @param string $comment |
| 143 | 143 | */ |
| 144 | - public function setComment ( $comment ) |
|
| 144 | + public function setComment($comment) |
|
| 145 | 145 | { |
| 146 | 146 | $this->comment = $comment; |
| 147 | 147 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | /** |
| 152 | 152 | * @param \Classes\Db\Constrant $primarykey |
| 153 | 153 | */ |
| 154 | - public function setPrimaryKey ( Constrant $primarykey ) |
|
| 154 | + public function setPrimaryKey(Constrant $primarykey) |
|
| 155 | 155 | { |
| 156 | 156 | $this->primarykey = $primarykey; |
| 157 | 157 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | /** |
| 162 | 162 | * @param \Classes\Db\Constrant $dependece |
| 163 | 163 | */ |
| 164 | - public function addDependece ( Constrant $dependece ) |
|
| 164 | + public function addDependece(Constrant $dependece) |
|
| 165 | 165 | { |
| 166 | 166 | $this->dependences[] = $dependece; |
| 167 | 167 | |
@@ -175,19 +175,19 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @return $this |
| 177 | 177 | */ |
| 178 | - public function createDependece ( $constraint_name , $table_name , $column_name , $schema = null ) |
|
| 178 | + public function createDependece($constraint_name, $table_name, $column_name, $schema = null) |
|
| 179 | 179 | { |
| 180 | - $objConstrantDependence = Constrant::getInstance () |
|
| 181 | - ->populate ( |
|
| 182 | - array ( |
|
| 183 | - 'constrant' => $constraint_name , |
|
| 184 | - 'schema' => $schema , |
|
| 185 | - 'table' => $table_name , |
|
| 180 | + $objConstrantDependence = Constrant::getInstance() |
|
| 181 | + ->populate( |
|
| 182 | + array( |
|
| 183 | + 'constrant' => $constraint_name, |
|
| 184 | + 'schema' => $schema, |
|
| 185 | + 'table' => $table_name, |
|
| 186 | 186 | 'column' => $column_name |
| 187 | 187 | ) |
| 188 | 188 | ); |
| 189 | 189 | |
| 190 | - $this->addDependece ( $objConstrantDependence ); |
|
| 190 | + $this->addDependece($objConstrantDependence); |
|
| 191 | 191 | |
| 192 | 192 | return $this; |
| 193 | 193 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | /** |
| 196 | 196 | * @param \Classes\Db\Constrant $reference |
| 197 | 197 | */ |
| 198 | - public function addRefFk ( Constrant $reference ) |
|
| 198 | + public function addRefFk(Constrant $reference) |
|
| 199 | 199 | { |
| 200 | 200 | $this->refForeingkey = $reference; |
| 201 | 201 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @return \Classes\Db\Constrant |
| 209 | 209 | */ |
| 210 | - public function getFks () |
|
| 210 | + public function getFks() |
|
| 211 | 211 | { |
| 212 | 212 | return $this->refForeingkey; |
| 213 | 213 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return \Classes\Db\Constrant[] |
| 219 | 219 | */ |
| 220 | - public function getDependences () |
|
| 220 | + public function getDependences() |
|
| 221 | 221 | { |
| 222 | 222 | return $this->dependences; |
| 223 | 223 | } |
@@ -225,9 +225,9 @@ discard block |
||
| 225 | 225 | /** |
| 226 | 226 | * @return bool |
| 227 | 227 | */ |
| 228 | - public function hasDependences () |
|
| 228 | + public function hasDependences() |
|
| 229 | 229 | { |
| 230 | - return (bool) count ( $this->dependences ); |
|
| 230 | + return (bool) count($this->dependences); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | * |
| 236 | 236 | * @return \Classes\Db\Constrant[] |
| 237 | 237 | */ |
| 238 | - public function getPrimaryKey () |
|
| 238 | + public function getPrimaryKey() |
|
| 239 | 239 | { |
| 240 | 240 | return $this->primarykey; |
| 241 | 241 | } |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | /** |
| 244 | 244 | * |
| 245 | 245 | */ |
| 246 | - public function getMaxLength () |
|
| 246 | + public function getMaxLength() |
|
| 247 | 247 | { |
| 248 | 248 | return $this->max_length; |
| 249 | 249 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | /** |
| 252 | 252 | * @return bool |
| 253 | 253 | */ |
| 254 | - public function hasSequence () |
|
| 254 | + public function hasSequence() |
|
| 255 | 255 | { |
| 256 | 256 | return (bool) $this->sequence; |
| 257 | 257 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | /** |
| 260 | 260 | * @return string |
| 261 | 261 | */ |
| 262 | - public function getSequence () |
|
| 262 | + public function getSequence() |
|
| 263 | 263 | { |
| 264 | 264 | return $this->sequence; |
| 265 | 265 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | /** |
| 268 | 268 | * @param string $sequence |
| 269 | 269 | */ |
| 270 | - public function setSequence ( $sequence ) |
|
| 270 | + public function setSequence($sequence) |
|
| 271 | 271 | { |
| 272 | 272 | $this->sequence = $sequence; |
| 273 | 273 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | /** |
| 276 | 276 | * @return boolean |
| 277 | 277 | */ |
| 278 | - public function isNullable () |
|
| 278 | + public function isNullable() |
|
| 279 | 279 | { |
| 280 | 280 | return $this->nullable; |
| 281 | 281 | } |
@@ -11,14 +11,14 @@ discard block |
||
| 11 | 11 | /** |
| 12 | 12 | * @author Pedro Alarcao <[email protected]> |
| 13 | 13 | */ |
| 14 | - final private function __construct () |
|
| 14 | + final private function __construct() |
|
| 15 | 15 | { |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * @return \Classes\Db\DbTable |
| 20 | 20 | */ |
| 21 | - public static function getInstance(){ |
|
| 21 | + public static function getInstance() { |
|
| 22 | 22 | return new self(); |
| 23 | 23 | } |
| 24 | 24 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | /** |
| 41 | 41 | * @var \Classes\Db\Column[] |
| 42 | 42 | */ |
| 43 | - private $columns = array (); |
|
| 43 | + private $columns = array(); |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * @var string |
@@ -50,25 +50,25 @@ discard block |
||
| 50 | 50 | /** |
| 51 | 51 | * @type \Classes\Db\Column[] |
| 52 | 52 | */ |
| 53 | - private $primarykeys = array (); |
|
| 53 | + private $primarykeys = array(); |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * @type \Classes\Db\Column[] |
| 57 | 57 | */ |
| 58 | - private $foreingkeys = array (); |
|
| 58 | + private $foreingkeys = array(); |
|
| 59 | 59 | |
| 60 | - private $dependence = array (); |
|
| 60 | + private $dependence = array(); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * @type string[] |
| 64 | 64 | */ |
| 65 | - private $sequence = array (); |
|
| 65 | + private $sequence = array(); |
|
| 66 | 66 | |
| 67 | - public function populate ( $array ) |
|
| 67 | + public function populate($array) |
|
| 68 | 68 | { |
| 69 | - $this->name = $array[ 'table' ]; |
|
| 70 | - $this->schema = isset( $array[ 'schema' ] ) ? $array[ 'schema' ] : null; |
|
| 71 | - $this->database = $array[ 'database' ]; |
|
| 69 | + $this->name = $array['table']; |
|
| 70 | + $this->schema = isset($array['schema']) ? $array['schema'] : null; |
|
| 71 | + $this->database = $array['database']; |
|
| 72 | 72 | |
| 73 | 73 | return $this; |
| 74 | 74 | } |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @param \Classes\Db\Column $column |
| 80 | 80 | */ |
| 81 | - public function addColumn ( Column $column ) |
|
| 81 | + public function addColumn(Column $column) |
|
| 82 | 82 | { |
| 83 | - $this->columns[ $column->getName () ] = $column; |
|
| 83 | + $this->columns[$column->getName()] = $column; |
|
| 84 | 84 | |
| 85 | 85 | return $this; |
| 86 | 86 | } |
@@ -90,24 +90,24 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @return \Classes\Db\Column |
| 92 | 92 | */ |
| 93 | - public function getColumn ( $columnName ) |
|
| 93 | + public function getColumn($columnName) |
|
| 94 | 94 | { |
| 95 | - return $this->columns[ $columnName ]; |
|
| 95 | + return $this->columns[$columnName]; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - public function hasColumn ( $columnName ) |
|
| 98 | + public function hasColumn($columnName) |
|
| 99 | 99 | { |
| 100 | - return isset( $this->columns[ $columnName ] ); |
|
| 100 | + return isset($this->columns[$columnName]); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * @return \Classes\Db\Column[] |
| 105 | 105 | */ |
| 106 | - public function getPrimaryKeys () |
|
| 106 | + public function getPrimaryKeys() |
|
| 107 | 107 | { |
| 108 | - if ( empty ( $this->primarykeys ) ) |
|
| 108 | + if (empty ($this->primarykeys)) |
|
| 109 | 109 | { |
| 110 | - $this->primarykeys = array_filter ( $this->columns , function ( $column ){ return $column->isPrimaryKey (); } ); |
|
| 110 | + $this->primarykeys = array_filter($this->columns, function($column) { return $column->isPrimaryKey(); } ); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | return $this->primarykeys; |
@@ -116,25 +116,25 @@ discard block |
||
| 116 | 116 | /** |
| 117 | 117 | * @return bool |
| 118 | 118 | */ |
| 119 | - public function hasPrimaryKey () |
|
| 119 | + public function hasPrimaryKey() |
|
| 120 | 120 | { |
| 121 | - if ( empty ( $this->sequence ) ) |
|
| 121 | + if (empty ($this->sequence)) |
|
| 122 | 122 | { |
| 123 | - $this->getPrimaryKeys (); |
|
| 123 | + $this->getPrimaryKeys(); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - return ! empty ( $this->sequence ); |
|
| 126 | + return ! empty ($this->sequence); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * @return \Classes\Db\Column[] |
| 131 | 131 | */ |
| 132 | - public function getForeingkeys () |
|
| 132 | + public function getForeingkeys() |
|
| 133 | 133 | { |
| 134 | 134 | |
| 135 | - if ( empty ( $this->foreingkeys ) ) |
|
| 135 | + if (empty ($this->foreingkeys)) |
|
| 136 | 136 | { |
| 137 | - $this->foreingkeys = array_filter ( $this->columns , function ( $column ){ return $column->isForeingkey (); } ); |
|
| 137 | + $this->foreingkeys = array_filter($this->columns, function($column) { return $column->isForeingkey(); } ); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | return $this->foreingkeys; |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | /** |
| 145 | 145 | * @return \Classes\Db\Column[] |
| 146 | 146 | */ |
| 147 | - public function getDependences () |
|
| 147 | + public function getDependences() |
|
| 148 | 148 | { |
| 149 | - if ( empty ( $this->dependence ) ) |
|
| 149 | + if (empty ($this->dependence)) |
|
| 150 | 150 | { |
| 151 | - $this->dependence = array_filter ( $this->columns , function ( $column ){ return $column->hasDependence (); } ); |
|
| 151 | + $this->dependence = array_filter($this->columns, function($column) { return $column->hasDependence(); } ); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | return $this->dependence; |
@@ -157,11 +157,11 @@ discard block |
||
| 157 | 157 | /** |
| 158 | 158 | * @return string[] |
| 159 | 159 | */ |
| 160 | - public function getSequences () |
|
| 160 | + public function getSequences() |
|
| 161 | 161 | { |
| 162 | - if ( empty ( $this->sequence ) ) |
|
| 162 | + if (empty ($this->sequence)) |
|
| 163 | 163 | { |
| 164 | - $this->sequence = array_filter ( $this->columns , function ( $column ){ return $column->hasSequence (); } ); |
|
| 164 | + $this->sequence = array_filter($this->columns, function($column) { return $column->hasSequence(); } ); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | return $this->sequence; |
@@ -170,20 +170,20 @@ discard block |
||
| 170 | 170 | /** |
| 171 | 171 | * @return bool |
| 172 | 172 | */ |
| 173 | - public function hasSequences () |
|
| 173 | + public function hasSequences() |
|
| 174 | 174 | { |
| 175 | - if ( empty ( $this->sequence ) ) |
|
| 175 | + if (empty ($this->sequence)) |
|
| 176 | 176 | { |
| 177 | - $this->getSequences (); |
|
| 177 | + $this->getSequences(); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - return ! empty ( $this->sequence ); |
|
| 180 | + return ! empty ($this->sequence); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
| 184 | 184 | * @return \Classes\Db\Column[] |
| 185 | 185 | */ |
| 186 | - public function getColumns () |
|
| 186 | + public function getColumns() |
|
| 187 | 187 | { |
| 188 | 188 | return $this->columns; |
| 189 | 189 | } |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | /** |
| 192 | 192 | * @return string |
| 193 | 193 | */ |
| 194 | - public function getName () |
|
| 194 | + public function getName() |
|
| 195 | 195 | { |
| 196 | 196 | return $this->name; |
| 197 | 197 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | /** |
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | - public function getSchema () |
|
| 202 | + public function getSchema() |
|
| 203 | 203 | { |
| 204 | 204 | return $this->schema; |
| 205 | 205 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | /** |
| 208 | 208 | * @return bool |
| 209 | 209 | */ |
| 210 | - public function hasSchema () |
|
| 210 | + public function hasSchema() |
|
| 211 | 211 | { |
| 212 | 212 | return (bool) $this->schema; |
| 213 | 213 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | /** |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | - public function getDatabase () |
|
| 218 | + public function getDatabase() |
|
| 219 | 219 | { |
| 220 | 220 | return $this->database; |
| 221 | 221 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | /** |
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | - public function getNamespace () |
|
| 226 | + public function getNamespace() |
|
| 227 | 227 | { |
| 228 | 228 | return $this->namespace; |
| 229 | 229 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | /** |
| 232 | 232 | * @param string $Namespace |
| 233 | 233 | */ |
| 234 | - public function setNamespace ( $namespace ) |
|
| 234 | + public function setNamespace($namespace) |
|
| 235 | 235 | { |
| 236 | 236 | $this->namespace = $namespace; |
| 237 | 237 | } |
@@ -21,11 +21,11 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @author Pedro Alarcao <[email protected]> |
| 23 | 23 | */ |
| 24 | - final private function __construct () |
|
| 24 | + final private function __construct() |
|
| 25 | 25 | { |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - public static function getInstance () |
|
| 28 | + public static function getInstance() |
|
| 29 | 29 | { |
| 30 | 30 | return new self(); |
| 31 | 31 | } |
@@ -55,31 +55,31 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return Constrant |
| 57 | 57 | */ |
| 58 | - public function populate ( $array ) |
|
| 58 | + public function populate($array) |
|
| 59 | 59 | { |
| 60 | - if ( isset( $array[ 'schema' ] ) ) |
|
| 60 | + if (isset($array['schema'])) |
|
| 61 | 61 | { |
| 62 | - $this->schema = $array[ 'schema' ]; |
|
| 62 | + $this->schema = $array['schema']; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $this->constrant = $array[ 'constrant' ]; |
|
| 66 | - $this->table = $array[ 'table' ]; |
|
| 67 | - $this->column = $array[ 'column' ]; |
|
| 65 | + $this->constrant = $array['constrant']; |
|
| 66 | + $this->table = $array['table']; |
|
| 67 | + $this->column = $array['column']; |
|
| 68 | 68 | |
| 69 | 69 | return $this; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function getDatabase (){ } |
|
| 72 | + public function getDatabase() { } |
|
| 73 | 73 | |
| 74 | 74 | /** |
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | - public function getNameConstrant () |
|
| 77 | + public function getNameConstrant() |
|
| 78 | 78 | { |
| 79 | 79 | return $this->constrant; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public function hasSchema () |
|
| 82 | + public function hasSchema() |
|
| 83 | 83 | { |
| 84 | 84 | return (bool) $this->schema; |
| 85 | 85 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | /** |
| 88 | 88 | * @return string |
| 89 | 89 | */ |
| 90 | - public function getSchema () |
|
| 90 | + public function getSchema() |
|
| 91 | 91 | { |
| 92 | 92 | return $this->schema; |
| 93 | 93 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | /** |
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | - public function getTable () |
|
| 98 | + public function getTable() |
|
| 99 | 99 | { |
| 100 | 100 | return $this->table; |
| 101 | 101 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | /** |
| 104 | 104 | * @return string |
| 105 | 105 | */ |
| 106 | - public function getColumn () |
|
| 106 | + public function getColumn() |
|
| 107 | 107 | { |
| 108 | 108 | return $this->column; |
| 109 | 109 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * @type string[] |
| 20 | 20 | */ |
| 21 | - public $location = array (); |
|
| 21 | + public $location = array(); |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * caminho de pastas Base |
@@ -37,154 +37,154 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | private $driver; |
| 39 | 39 | |
| 40 | - public function __construct ( Config $config ) |
|
| 40 | + public function __construct(Config $config) |
|
| 41 | 41 | { |
| 42 | - $this->config = $config->getAdapterConfig (); |
|
| 43 | - $this->driver = $config->getAdapterDriver (); |
|
| 44 | - $this->parseLocation ( $config->_basePath ); |
|
| 42 | + $this->config = $config->getAdapterConfig(); |
|
| 43 | + $this->driver = $config->getAdapterDriver(); |
|
| 44 | + $this->parseLocation($config->_basePath); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Analisa os caminhos das pastas base |
| 49 | 49 | */ |
| 50 | - public function parseLocation ( $basePath ) |
|
| 50 | + public function parseLocation($basePath) |
|
| 51 | 51 | { |
| 52 | 52 | |
| 53 | - $arrBase = array ( |
|
| 54 | - $basePath , |
|
| 53 | + $arrBase = array( |
|
| 54 | + $basePath, |
|
| 55 | 55 | $this->config->path |
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | - $this->baseLocation = implode ( DIRECTORY_SEPARATOR , array_filter ( $arrBase ) ); |
|
| 58 | + $this->baseLocation = implode(DIRECTORY_SEPARATOR, array_filter($arrBase)); |
|
| 59 | 59 | |
| 60 | 60 | # pasta com nome do driver do banco |
| 61 | 61 | $driverBase = ''; |
| 62 | - if ( $this->config->{"folder-database"} ) |
|
| 62 | + if ($this->config->{"folder-database"} ) |
|
| 63 | 63 | { |
| 64 | - $classDriver = explode ( '\\' , get_class ( $this->driver ) ); |
|
| 65 | - $driverBase = end ( $classDriver ); |
|
| 64 | + $classDriver = explode('\\', get_class($this->driver)); |
|
| 65 | + $driverBase = end($classDriver); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - if ( $this->config->hasSchemas () ) |
|
| 68 | + if ($this->config->hasSchemas()) |
|
| 69 | 69 | { |
| 70 | 70 | |
| 71 | - $schemas = $this->config->getSchemas (); |
|
| 72 | - foreach ( $schemas as $schema ) |
|
| 71 | + $schemas = $this->config->getSchemas(); |
|
| 72 | + foreach ($schemas as $schema) |
|
| 73 | 73 | { |
| 74 | - $arrUrl = array ( |
|
| 75 | - $this->baseLocation , |
|
| 76 | - $driverBase , |
|
| 77 | - $this->getClassName ( $schema ) |
|
| 74 | + $arrUrl = array( |
|
| 75 | + $this->baseLocation, |
|
| 76 | + $driverBase, |
|
| 77 | + $this->getClassName($schema) |
|
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | - $this->location[ $schema ] = implode ( DIRECTORY_SEPARATOR , array_filter ( $arrUrl ) ); |
|
| 81 | - unset( $arrUrl ); |
|
| 80 | + $this->location[$schema] = implode(DIRECTORY_SEPARATOR, array_filter($arrUrl)); |
|
| 81 | + unset($arrUrl); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | |
| 85 | 85 | } else |
| 86 | 86 | { |
| 87 | - $baseLocation = implode ( |
|
| 88 | - DIRECTORY_SEPARATOR , array_filter ( array ( |
|
| 89 | - $this->baseLocation , |
|
| 90 | - $driverBase , |
|
| 91 | - $this->getClassName ( $this->getConfig ()->getDatabase () ) |
|
| 87 | + $baseLocation = implode( |
|
| 88 | + DIRECTORY_SEPARATOR, array_filter(array( |
|
| 89 | + $this->baseLocation, |
|
| 90 | + $driverBase, |
|
| 91 | + $this->getClassName($this->getConfig()->getDatabase()) |
|
| 92 | 92 | ) |
| 93 | 93 | ) |
| 94 | 94 | ); |
| 95 | - $this->location = array ( $baseLocation ); |
|
| 95 | + $this->location = array($baseLocation); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * @return AdapterConfig\AbstractAdapter |
| 101 | 101 | */ |
| 102 | - public function getConfig () |
|
| 102 | + public function getConfig() |
|
| 103 | 103 | { |
| 104 | 104 | return $this->config; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /* Get current time */ |
| 108 | - public function startTime () |
|
| 108 | + public function startTime() |
|
| 109 | 109 | { |
| 110 | 110 | echo "Starting..\n"; |
| 111 | - $this->startTime = microtime ( true ); |
|
| 111 | + $this->startTime = microtime(true); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - private function getRunTime () |
|
| 114 | + private function getRunTime() |
|
| 115 | 115 | { |
| 116 | - return round ( ( microtime ( true ) - $this->startTime ) , 3 ); |
|
| 116 | + return round((microtime(true) - $this->startTime), 3); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Executa o Make, criando arquivos e Diretorios |
| 121 | 121 | */ |
| 122 | - public function run () |
|
| 122 | + public function run() |
|
| 123 | 123 | { |
| 124 | - $this->startTime (); |
|
| 125 | - $this->driver->runDatabase (); |
|
| 126 | - $max = $this->driver->getTotalTables () * count ( $this->factoryMakerFile () ); |
|
| 124 | + $this->startTime(); |
|
| 125 | + $this->driver->runDatabase(); |
|
| 126 | + $max = $this->driver->getTotalTables() * count($this->factoryMakerFile()); |
|
| 127 | 127 | $cur = 0; |
| 128 | 128 | |
| 129 | 129 | |
| 130 | - foreach ( $this->location as $schema => $location ) |
|
| 130 | + foreach ($this->location as $schema => $location) |
|
| 131 | 131 | { |
| 132 | - foreach ( $this->factoryMakerFile () as $objMakeFile ) |
|
| 132 | + foreach ($this->factoryMakerFile() as $objMakeFile) |
|
| 133 | 133 | { |
| 134 | - $path = $location . DIRECTORY_SEPARATOR . $objMakeFile->getPastName (); |
|
| 135 | - self::makeDir ( $path ); |
|
| 134 | + $path = $location . DIRECTORY_SEPARATOR . $objMakeFile->getPastName(); |
|
| 135 | + self::makeDir($path); |
|
| 136 | 136 | |
| 137 | - if ( $objMakeFile->getParentFileTpl () != '' ) |
|
| 137 | + if ($objMakeFile->getParentFileTpl() != '') |
|
| 138 | 138 | { |
| 139 | 139 | $fileAbstract = $this->baseLocation |
| 140 | 140 | . DIRECTORY_SEPARATOR |
| 141 | - . $objMakeFile->getParentClass () . '.php'; |
|
| 141 | + . $objMakeFile->getParentClass() . '.php'; |
|
| 142 | 142 | |
| 143 | - $tplAbstract = $this->getParsedTplContents ( $objMakeFile->getParentFileTpl () ); |
|
| 144 | - self::makeSourcer ( $fileAbstract , $tplAbstract , $objMakeFile->isOverwrite () ); |
|
| 145 | - unset( $fileAbstract , $tplAbstract ); |
|
| 143 | + $tplAbstract = $this->getParsedTplContents($objMakeFile->getParentFileTpl()); |
|
| 144 | + self::makeSourcer($fileAbstract, $tplAbstract, $objMakeFile->isOverwrite()); |
|
| 145 | + unset($fileAbstract, $tplAbstract); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - foreach ( $this->driver->getTables ( $schema ) as $key => $objTables ) |
|
| 148 | + foreach ($this->driver->getTables($schema) as $key => $objTables) |
|
| 149 | 149 | { |
| 150 | - $total = ceil ( $cur / $max ) * 100; |
|
| 151 | - printf ( "\r Creating: %6.2f%%" , $total ); |
|
| 152 | - $cur ++; |
|
| 150 | + $total = ceil($cur / $max) * 100; |
|
| 151 | + printf("\r Creating: %6.2f%%", $total); |
|
| 152 | + $cur++; |
|
| 153 | 153 | |
| 154 | 154 | $file = $path |
| 155 | 155 | . DIRECTORY_SEPARATOR |
| 156 | - . self::getClassName ( $objTables->getName () ) |
|
| 156 | + . self::getClassName($objTables->getName()) |
|
| 157 | 157 | . '.php'; |
| 158 | 158 | |
| 159 | 159 | |
| 160 | - $tpl = $this->getParsedTplContents ( |
|
| 161 | - $objMakeFile->getFileTpl () , |
|
| 162 | - $objMakeFile->parseRelation ( $this , $objTables ) |
|
| 163 | - , $objTables , $objMakeFile |
|
| 160 | + $tpl = $this->getParsedTplContents( |
|
| 161 | + $objMakeFile->getFileTpl(), |
|
| 162 | + $objMakeFile->parseRelation($this, $objTables) |
|
| 163 | + , $objTables, $objMakeFile |
|
| 164 | 164 | |
| 165 | 165 | ); |
| 166 | - self::makeSourcer ( $file , $tpl , $objMakeFile->isOverwrite () ); |
|
| 166 | + self::makeSourcer($file, $tpl, $objMakeFile->isOverwrite()); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - $this->reportProcess ( $cur ); |
|
| 172 | + $this->reportProcess($cur); |
|
| 173 | 173 | echo "\n\033[1;32mSuccessfully process finished!\n\033[0m"; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - private function reportProcess ( $countFiles ) |
|
| 176 | + private function reportProcess($countFiles) |
|
| 177 | 177 | { |
| 178 | - if ( $this->config->isStatusEnabled () ) |
|
| 178 | + if ($this->config->isStatusEnabled()) |
|
| 179 | 179 | { |
| 180 | - $databases = count ( $this->location ); |
|
| 181 | - $countDir = $this->countDiretory (); |
|
| 182 | - $totalTable = $this->driver->getTotalTables (); |
|
| 180 | + $databases = count($this->location); |
|
| 181 | + $countDir = $this->countDiretory(); |
|
| 182 | + $totalTable = $this->driver->getTotalTables(); |
|
| 183 | 183 | echo "\n------"; |
| 184 | - printf ( "\n\r-Files generated:%s" , $countFiles ); |
|
| 185 | - printf ( "\n\r-Diretory generated:%s" , $databases * $countDir ); |
|
| 186 | - printf ( "\n\r-Scanned tables:%s" , $totalTable ); |
|
| 187 | - printf ( "\n\r-Execution time: %ssec" , $this->getRunTime () ); |
|
| 184 | + printf("\n\r-Files generated:%s", $countFiles); |
|
| 185 | + printf("\n\r-Diretory generated:%s", $databases * $countDir); |
|
| 186 | + printf("\n\r-Scanned tables:%s", $totalTable); |
|
| 187 | + printf("\n\r-Execution time: %ssec", $this->getRunTime()); |
|
| 188 | 188 | echo "\n------"; |
| 189 | 189 | } |
| 190 | 190 | } |
@@ -194,9 +194,9 @@ discard block |
||
| 194 | 194 | * |
| 195 | 195 | * @return AbstractAdapter[] |
| 196 | 196 | */ |
| 197 | - public function factoryMakerFile () |
|
| 197 | + public function factoryMakerFile() |
|
| 198 | 198 | { |
| 199 | - return $this->config->getMakeFileInstances (); |
|
| 199 | + return $this->config->getMakeFileInstances(); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -204,14 +204,14 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @return int |
| 206 | 206 | */ |
| 207 | - public function countDiretory () |
|
| 207 | + public function countDiretory() |
|
| 208 | 208 | { |
| 209 | 209 | $dir = 0; |
| 210 | - foreach ( $this->factoryMakerFile () as $abstractAdapter ) |
|
| 210 | + foreach ($this->factoryMakerFile() as $abstractAdapter) |
|
| 211 | 211 | { |
| 212 | - if ( $abstractAdapter->hasDiretory () ) |
|
| 212 | + if ($abstractAdapter->hasDiretory()) |
|
| 213 | 213 | { |
| 214 | - $dir ++; |
|
| 214 | + $dir++; |
|
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
@@ -226,23 +226,23 @@ discard block |
||
| 226 | 226 | * |
| 227 | 227 | * @return String |
| 228 | 228 | */ |
| 229 | - protected function getParsedTplContents ( $tplFile , $vars = array () , \Classes\Db\DbTable $objTables = null , $objMakeFile = null ) |
|
| 229 | + protected function getParsedTplContents($tplFile, $vars = array(), \Classes\Db\DbTable $objTables = null, $objMakeFile = null) |
|
| 230 | 230 | { |
| 231 | 231 | |
| 232 | - $arrUrl = array ( |
|
| 233 | - __DIR__ , |
|
| 234 | - 'templates' , |
|
| 235 | - $this->config->framework , |
|
| 232 | + $arrUrl = array( |
|
| 233 | + __DIR__, |
|
| 234 | + 'templates', |
|
| 235 | + $this->config->framework, |
|
| 236 | 236 | $tplFile |
| 237 | 237 | ); |
| 238 | 238 | |
| 239 | - $filePath = implode ( DIRECTORY_SEPARATOR , filter_var_array ( $arrUrl ) ); |
|
| 239 | + $filePath = implode(DIRECTORY_SEPARATOR, filter_var_array($arrUrl)); |
|
| 240 | 240 | |
| 241 | - extract ( $vars ); |
|
| 242 | - ob_start (); |
|
| 241 | + extract($vars); |
|
| 242 | + ob_start(); |
|
| 243 | 243 | require $filePath; |
| 244 | - $data = ob_get_contents (); |
|
| 245 | - ob_end_clean (); |
|
| 244 | + $data = ob_get_contents(); |
|
| 245 | + ob_end_clean(); |
|
| 246 | 246 | |
| 247 | 247 | return $data; |
| 248 | 248 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | protected $fileTpl = "entity.php"; |
| 23 | 23 | protected $overwrite = true; |
| 24 | 24 | |
| 25 | - protected $validFunc = array (); |
|
| 25 | + protected $validFunc = array(); |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * @param \Classes\MakerFile $makerFile |
@@ -30,68 +30,68 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return array |
| 32 | 32 | */ |
| 33 | - public function parseRelation ( \Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable ) |
|
| 33 | + public function parseRelation(\Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable) |
|
| 34 | 34 | { |
| 35 | 35 | |
| 36 | - $parents = array (); |
|
| 37 | - $depends = array (); |
|
| 38 | - foreach ( $dbTable->getForeingkeys () as $fks ) |
|
| 36 | + $parents = array(); |
|
| 37 | + $depends = array(); |
|
| 38 | + foreach ($dbTable->getForeingkeys() as $fks) |
|
| 39 | 39 | { |
| 40 | - $constrant = $fks->getFks (); |
|
| 40 | + $constrant = $fks->getFks(); |
|
| 41 | 41 | $name = |
| 42 | 42 | 'Parent' |
| 43 | 43 | . ZendFrameworkOne::SEPARETOR |
| 44 | - . AbstractMaker::getClassName ( $constrant->getTable () ) |
|
| 44 | + . AbstractMaker::getClassName($constrant->getTable()) |
|
| 45 | 45 | . ZendFrameworkOne::SEPARETOR |
| 46 | 46 | . 'By' |
| 47 | 47 | . ZendFrameworkOne::SEPARETOR |
| 48 | 48 | . $fks->getName(); |
| 49 | 49 | |
| 50 | - $parents[] = array ( |
|
| 51 | - 'class' => $makerFile->getConfig () |
|
| 52 | - ->createClassNamespace ( $constrant ) |
|
| 50 | + $parents[] = array( |
|
| 51 | + 'class' => $makerFile->getConfig() |
|
| 52 | + ->createClassNamespace($constrant) |
|
| 53 | 53 | . ZendFrameworkOne::SEPARETOR |
| 54 | - . AbstractMaker::getClassName ( $constrant->getTable () ), |
|
| 55 | - 'function' => AbstractMaker::getClassName ( $name ), |
|
| 56 | - 'table' => $constrant->getTable (), |
|
| 57 | - 'column' => $fks->getName (), |
|
| 58 | - 'name' => $constrant->getNameConstrant (), |
|
| 54 | + . AbstractMaker::getClassName($constrant->getTable()), |
|
| 55 | + 'function' => AbstractMaker::getClassName($name), |
|
| 56 | + 'table' => $constrant->getTable(), |
|
| 57 | + 'column' => $fks->getName(), |
|
| 58 | + 'name' => $constrant->getNameConstrant(), |
|
| 59 | 59 | ); |
| 60 | - unset( $name ); |
|
| 60 | + unset($name); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - foreach ( $dbTable->getDependences () as $objColumn ) |
|
| 63 | + foreach ($dbTable->getDependences() as $objColumn) |
|
| 64 | 64 | { |
| 65 | - foreach ( $objColumn->getDependences () as $dependence ) |
|
| 65 | + foreach ($objColumn->getDependences() as $dependence) |
|
| 66 | 66 | { |
| 67 | 67 | $name = |
| 68 | 68 | 'Depend' |
| 69 | 69 | . ZendFrameworkOne::SEPARETOR |
| 70 | - . AbstractMaker::getClassName ( $dependence->getTable () ) |
|
| 70 | + . AbstractMaker::getClassName($dependence->getTable()) |
|
| 71 | 71 | . ZendFrameworkOne::SEPARETOR |
| 72 | 72 | . 'By' |
| 73 | 73 | . ZendFrameworkOne::SEPARETOR |
| 74 | 74 | . $fks->getName(); |
| 75 | 75 | |
| 76 | - if ( !key_exists ( $name, $this->validFunc ) ) |
|
| 76 | + if ( ! key_exists($name, $this->validFunc)) |
|
| 77 | 77 | { |
| 78 | - $this->validFunc[ $name ] = true; |
|
| 79 | - $depends[] = array ( |
|
| 80 | - 'class' => $makerFile->getConfig () |
|
| 81 | - ->createClassNamespace ( $dependence ) |
|
| 78 | + $this->validFunc[$name] = true; |
|
| 79 | + $depends[] = array( |
|
| 80 | + 'class' => $makerFile->getConfig() |
|
| 81 | + ->createClassNamespace($dependence) |
|
| 82 | 82 | . ZendFrameworkOne::SEPARETOR |
| 83 | - . AbstractMaker::getClassName ( $dependence->getTable () ), |
|
| 84 | - 'function' => AbstractMaker::getClassName ( $name ), |
|
| 85 | - 'table' => $dependence->getTable (), |
|
| 86 | - 'column' => $dependence->getColumn (), |
|
| 87 | - 'name' => $dependence->getNameConstrant () |
|
| 83 | + . AbstractMaker::getClassName($dependence->getTable()), |
|
| 84 | + 'function' => AbstractMaker::getClassName($name), |
|
| 85 | + 'table' => $dependence->getTable(), |
|
| 86 | + 'column' => $dependence->getColumn(), |
|
| 87 | + 'name' => $dependence->getNameConstrant() |
|
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | - unset( $name ); |
|
| 90 | + unset($name); |
|
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - return array ( |
|
| 94 | + return array( |
|
| 95 | 95 | 'parents' => $parents, |
| 96 | 96 | 'depends' => $depends |
| 97 | 97 | ); |