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