@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | $configIni = isset( $argv[ 'name-ini' ] ) |
193 | 193 | ? $argv[ 'name-ini' ] |
194 | 194 | : $this->_basePath |
195 | - . $this->configIniDefault; |
|
195 | + . $this->configIniDefault; |
|
196 | 196 | |
197 | 197 | $configTemp = $this->loadIniFile ( realpath ( $configIni ) ); |
198 | 198 | $configCurrent = self::parseConfigEnv ( $configTemp , $argv ); |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | { |
207 | 207 | $frameworks = implode ( "\n\t" , $this->frameworkList ); |
208 | 208 | throw new \Exception( "list of frameworks: \n\t\033[1;33m" . $frameworks |
209 | - . "\n\033[0m" ); |
|
209 | + . "\n\033[0m" ); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | return $argv + array_filter ( $configCurrent ); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | /** |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - private $argv = array (); |
|
55 | + private $argv = array(); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @var \Classes\AdapterConfig\AbstractAdapter |
@@ -64,46 +64,46 @@ discard block |
||
64 | 64 | */ |
65 | 65 | private $adapterDriver; |
66 | 66 | |
67 | - private $frameworkList = array ( |
|
68 | - 'none' , |
|
69 | - 'zf1' , |
|
67 | + private $frameworkList = array( |
|
68 | + 'none', |
|
69 | + 'zf1', |
|
70 | 70 | 'phalcon' |
71 | 71 | ); |
72 | 72 | |
73 | - private $parameterList = array ( |
|
74 | - 'init' => 'Creates the necessary configuration file to start using the orm-generator.' , |
|
75 | - 'name-ini' => 'reference to another .ini file configuration (relative path).' , |
|
76 | - 'config-env' => 'orm-generator configuration environment.' , |
|
77 | - 'framework' => 'name framework used, which has the contents of the database configurations and framework template.' , |
|
78 | - 'driver' => 'database driver name (Ex.: pgsql).' , |
|
79 | - 'database' => 'database name.' , |
|
80 | - 'schema' => 'database schema name (one or more than one).' , |
|
81 | - 'tables' => 'table name (parameter can be used more then once).' , |
|
82 | - 'clean-trash' => 'delete all files that do not belong to your Database due' , |
|
83 | - 'status' => 'show status of implementation carried out after completing the process.' , |
|
84 | - 'version' => 'shows the version of orm-generator.' , |
|
85 | - 'help' => "help command explaining all the options and manner of use." , |
|
86 | - 'path' => "specify where to create the files (default is current directory)." , |
|
73 | + private $parameterList = array( |
|
74 | + 'init' => 'Creates the necessary configuration file to start using the orm-generator.', |
|
75 | + 'name-ini' => 'reference to another .ini file configuration (relative path).', |
|
76 | + 'config-env' => 'orm-generator configuration environment.', |
|
77 | + 'framework' => 'name framework used, which has the contents of the database configurations and framework template.', |
|
78 | + 'driver' => 'database driver name (Ex.: pgsql).', |
|
79 | + 'database' => 'database name.', |
|
80 | + 'schema' => 'database schema name (one or more than one).', |
|
81 | + 'tables' => 'table name (parameter can be used more then once).', |
|
82 | + 'clean-trash' => 'delete all files that do not belong to your Database due', |
|
83 | + 'status' => 'show status of implementation carried out after completing the process.', |
|
84 | + 'version' => 'shows the version of orm-generator.', |
|
85 | + 'help' => "help command explaining all the options and manner of use.", |
|
86 | + 'path' => "specify where to create the files (default is current directory).", |
|
87 | 87 | ); |
88 | 88 | |
89 | - public function __construct ( $argv , $basePath , $numArgs ) |
|
89 | + public function __construct($argv, $basePath, $numArgs) |
|
90 | 90 | { |
91 | - if ( array_key_exists ( 'help' , $argv ) or ( $numArgs > 1 |
|
92 | - && count ( $argv ) < 1 ) |
|
91 | + if (array_key_exists('help', $argv) or ($numArgs > 1 |
|
92 | + && count($argv) < 1) |
|
93 | 93 | ) |
94 | 94 | { |
95 | - die ( $this->getUsage () ); |
|
95 | + die ($this->getUsage()); |
|
96 | 96 | } |
97 | - if ( array_key_exists ( 'version' , $argv ) ) |
|
97 | + if (array_key_exists('version', $argv)) |
|
98 | 98 | { |
99 | - die ( $this->getVersion () ); |
|
99 | + die ($this->getVersion()); |
|
100 | 100 | } |
101 | - if ( array_key_exists ( 'status' , $argv ) ) |
|
101 | + if (array_key_exists('status', $argv)) |
|
102 | 102 | { |
103 | - $argv[ 'status' ] = true; |
|
103 | + $argv['status'] = true; |
|
104 | 104 | } |
105 | 105 | |
106 | - $this->argv = $this->parseConfig ( $basePath , $argv ); |
|
106 | + $this->argv = $this->parseConfig($basePath, $argv); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -111,10 +111,10 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @return string |
113 | 113 | */ |
114 | - public function getUsage () |
|
114 | + public function getUsage() |
|
115 | 115 | { |
116 | - $version = $this->getVersion (); |
|
117 | - $list = $this->renderParam (); |
|
116 | + $version = $this->getVersion(); |
|
117 | + $list = $this->renderParam(); |
|
118 | 118 | |
119 | 119 | return <<<EOF |
120 | 120 | parameters: |
@@ -125,12 +125,12 @@ discard block |
||
125 | 125 | EOF; |
126 | 126 | } |
127 | 127 | |
128 | - public function renderParam () |
|
128 | + public function renderParam() |
|
129 | 129 | { |
130 | 130 | $return = ""; |
131 | - foreach ( $this->parameterList as $param => $desc ) |
|
131 | + foreach ($this->parameterList as $param => $desc) |
|
132 | 132 | { |
133 | - if ( strlen ( $param ) < 5 ) |
|
133 | + if (strlen($param) < 5) |
|
134 | 134 | { |
135 | 135 | $return .= "\t--" . $param . "\t\t: " . $desc . "\n"; |
136 | 136 | } else |
@@ -143,37 +143,37 @@ discard block |
||
143 | 143 | return $return; |
144 | 144 | } |
145 | 145 | |
146 | - public function checkHasNewVersion () |
|
146 | + public function checkHasNewVersion() |
|
147 | 147 | { |
148 | - if ( ! ini_get ( 'file_get_contents' ) ) |
|
148 | + if ( ! ini_get('file_get_contents')) |
|
149 | 149 | { |
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | - $opts = array ( |
|
154 | - 'http' => array ( |
|
155 | - 'method' => 'GET' , |
|
156 | - 'header' => array ( |
|
153 | + $opts = array( |
|
154 | + 'http' => array( |
|
155 | + 'method' => 'GET', |
|
156 | + 'header' => array( |
|
157 | 157 | 'User-Agent: PHP' |
158 | 158 | ) |
159 | 159 | ) |
160 | 160 | ); |
161 | 161 | $context = stream_context_create($opts); |
162 | - $tags = json_decode ( file_get_contents ( "https://api.github.com/repos/pedro151/orm-generator/tags" , false, $context) ); |
|
162 | + $tags = json_decode(file_get_contents("https://api.github.com/repos/pedro151/orm-generator/tags", false, $context)); |
|
163 | 163 | |
164 | 164 | |
165 | - $lastVersion = preg_replace("/[^0-9.]/", "", $tags[ 0 ]->name); |
|
166 | - if ( $lastVersion > static::$version ) |
|
165 | + $lastVersion = preg_replace("/[^0-9.]/", "", $tags[0]->name); |
|
166 | + if ($lastVersion > static::$version) |
|
167 | 167 | { |
168 | 168 | return "\033[0;31mThere is a new version $lastVersion available:\033[0m https://github.com/pedro151/orm-generator\n"; |
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - public function getVersion () |
|
172 | + public function getVersion() |
|
173 | 173 | { |
174 | 174 | $version = static::$version; |
175 | 175 | |
176 | - return "ORM Generator By: Pedro Alarcao Version: $version\n".$this->checkHasNewVersion(); |
|
176 | + return "ORM Generator By: Pedro Alarcao Version: $version\n" . $this->checkHasNewVersion(); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -185,31 +185,31 @@ discard block |
||
185 | 185 | * @return array |
186 | 186 | * @throws \Exception |
187 | 187 | */ |
188 | - private function parseConfig ( $basePath , $argv ) |
|
188 | + private function parseConfig($basePath, $argv) |
|
189 | 189 | { |
190 | 190 | $this->_basePath = $basePath; |
191 | 191 | |
192 | - $configIni = isset( $argv[ 'name-ini' ] ) |
|
193 | - ? $argv[ 'name-ini' ] |
|
192 | + $configIni = isset($argv['name-ini']) |
|
193 | + ? $argv['name-ini'] |
|
194 | 194 | : $this->_basePath |
195 | 195 | . $this->configIniDefault; |
196 | 196 | |
197 | - $configTemp = $this->loadIniFile ( realpath ( $configIni ) ); |
|
198 | - $configCurrent = self::parseConfigEnv ( $configTemp , $argv ); |
|
197 | + $configTemp = $this->loadIniFile(realpath($configIni)); |
|
198 | + $configCurrent = self::parseConfigEnv($configTemp, $argv); |
|
199 | 199 | |
200 | - if ( ! isset( $configCurrent[ 'framework' ] ) ) |
|
200 | + if ( ! isset($configCurrent['framework'])) |
|
201 | 201 | { |
202 | - throw new \Exception( "configure which framework you want to use! \n" ); |
|
202 | + throw new \Exception("configure which framework you want to use! \n"); |
|
203 | 203 | } |
204 | 204 | |
205 | - if ( ! in_array ( $configCurrent[ 'framework' ] , $this->frameworkList ) ) |
|
205 | + if ( ! in_array($configCurrent['framework'], $this->frameworkList)) |
|
206 | 206 | { |
207 | - $frameworks = implode ( "\n\t" , $this->frameworkList ); |
|
208 | - throw new \Exception( "list of frameworks: \n\t\033[1;33m" . $frameworks |
|
209 | - . "\n\033[0m" ); |
|
207 | + $frameworks = implode("\n\t", $this->frameworkList); |
|
208 | + throw new \Exception("list of frameworks: \n\t\033[1;33m" . $frameworks |
|
209 | + . "\n\033[0m"); |
|
210 | 210 | } |
211 | 211 | |
212 | - return $argv + array_filter ( $configCurrent ); |
|
212 | + return $argv + array_filter($configCurrent); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -219,24 +219,24 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @return string |
221 | 221 | */ |
222 | - private static function parseConfigEnv ( $configTemp , $argv ) |
|
222 | + private static function parseConfigEnv($configTemp, $argv) |
|
223 | 223 | { |
224 | - $thisSection = isset( $configTemp[ key ( $configTemp ) ][ 'config-env' ] ) |
|
225 | - ? $configTemp[ key ( |
|
224 | + $thisSection = isset($configTemp[key($configTemp)]['config-env']) |
|
225 | + ? $configTemp[key( |
|
226 | 226 | $configTemp |
227 | - ) ][ 'config-env' ] : null; |
|
227 | + )]['config-env'] : null; |
|
228 | 228 | |
229 | - $thisSection = isset( $argv[ 'config-env' ] ) ? $argv[ 'config-env' ] |
|
229 | + $thisSection = isset($argv['config-env']) ? $argv['config-env'] |
|
230 | 230 | : $thisSection; |
231 | 231 | |
232 | - if ( isset( $configTemp[ $thisSection ][ 'extends' ] ) ) |
|
232 | + if (isset($configTemp[$thisSection]['extends'])) |
|
233 | 233 | { |
234 | 234 | #faz marge da config principal com a config extendida |
235 | - return $configTemp[ $thisSection ] |
|
236 | - + $configTemp[ $configTemp[ $thisSection ][ 'extends' ] ]; |
|
235 | + return $configTemp[$thisSection] |
|
236 | + + $configTemp[$configTemp[$thisSection]['extends']]; |
|
237 | 237 | } |
238 | 238 | |
239 | - return $configTemp[ key ( $configTemp ) ]; |
|
239 | + return $configTemp[key($configTemp)]; |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -250,32 +250,32 @@ discard block |
||
250 | 250 | * @throws \Exception |
251 | 251 | * @return array |
252 | 252 | */ |
253 | - protected function loadIniFile ( $filename ) |
|
253 | + protected function loadIniFile($filename) |
|
254 | 254 | { |
255 | - if ( ! is_file ( $filename ) ) |
|
255 | + if ( ! is_file($filename)) |
|
256 | 256 | { |
257 | - throw new \Exception( "\033[0;31mError: configuration file does not exist! \033[0m\n" ); |
|
257 | + throw new \Exception("\033[0;31mError: configuration file does not exist! \033[0m\n"); |
|
258 | 258 | } |
259 | 259 | |
260 | - $loaded = parse_ini_file ( $filename , true ); |
|
261 | - $iniArray = array (); |
|
262 | - foreach ( $loaded as $key => $data ) |
|
260 | + $loaded = parse_ini_file($filename, true); |
|
261 | + $iniArray = array(); |
|
262 | + foreach ($loaded as $key => $data) |
|
263 | 263 | { |
264 | - $pieces = explode ( $this->sectionSeparator , $key ); |
|
265 | - $thisSection = trim ( $pieces[ 0 ] ); |
|
266 | - switch ( count ( $pieces ) ) |
|
264 | + $pieces = explode($this->sectionSeparator, $key); |
|
265 | + $thisSection = trim($pieces[0]); |
|
266 | + switch (count($pieces)) |
|
267 | 267 | { |
268 | 268 | case 1: |
269 | - $iniArray[ $thisSection ] = $data; |
|
269 | + $iniArray[$thisSection] = $data; |
|
270 | 270 | break; |
271 | 271 | |
272 | 272 | case 2: |
273 | - $extendedSection = trim ( $pieces[ 1 ] ); |
|
274 | - $iniArray[ $thisSection ] = array_merge ( array ( 'extends' => $extendedSection ) , $data ); |
|
273 | + $extendedSection = trim($pieces[1]); |
|
274 | + $iniArray[$thisSection] = array_merge(array('extends' => $extendedSection), $data); |
|
275 | 275 | break; |
276 | 276 | |
277 | 277 | default: |
278 | - throw new \Exception( "Section '$thisSection' may not extend multiple sections in $filename" ); |
|
278 | + throw new \Exception("Section '$thisSection' may not extend multiple sections in $filename"); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
@@ -288,16 +288,16 @@ discard block |
||
288 | 288 | * @return \Classes\AdapterConfig\AbstractAdapter |
289 | 289 | * |
290 | 290 | */ |
291 | - private function factoryConfig () |
|
291 | + private function factoryConfig() |
|
292 | 292 | { |
293 | - switch ( strtolower ( $this->argv[ 'framework' ] ) ) |
|
293 | + switch (strtolower($this->argv['framework'])) |
|
294 | 294 | { |
295 | 295 | case 'zf1': |
296 | - return new ZendFrameworkOne( $this->argv ); |
|
296 | + return new ZendFrameworkOne($this->argv); |
|
297 | 297 | case 'phalcon': |
298 | - return new Phalcon( $this->argv ); |
|
298 | + return new Phalcon($this->argv); |
|
299 | 299 | default: |
300 | - return new None( $this->argv ); |
|
300 | + return new None($this->argv); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | } |
@@ -309,33 +309,33 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @return AdaptersDriver\AbsractAdapter |
311 | 311 | */ |
312 | - private function factoryDriver ( AdapterConfig\AbstractAdapter $config ) |
|
312 | + private function factoryDriver(AdapterConfig\AbstractAdapter $config) |
|
313 | 313 | { |
314 | - switch ( $this->argv[ 'driver' ] ) |
|
314 | + switch ($this->argv['driver']) |
|
315 | 315 | { |
316 | 316 | case 'pgsql': |
317 | 317 | case 'pdo_pgsql': |
318 | - return new Pgsql( $config ); |
|
318 | + return new Pgsql($config); |
|
319 | 319 | case 'mysql': |
320 | 320 | case 'pdo_mysql': |
321 | - return new Mysql( $config ); |
|
321 | + return new Mysql($config); |
|
322 | 322 | case 'mssql': |
323 | - return new Mssql( $config ); |
|
323 | + return new Mssql($config); |
|
324 | 324 | case 'dblib': |
325 | - return new Dblib( $config ); |
|
325 | + return new Dblib($config); |
|
326 | 326 | case 'sqlsrv': |
327 | - return new Sqlsrv( $config ); |
|
327 | + return new Sqlsrv($config); |
|
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
332 | 332 | * @return AdapterConfig\AbstractAdapter |
333 | 333 | */ |
334 | - public function getAdapterConfig () |
|
334 | + public function getAdapterConfig() |
|
335 | 335 | { |
336 | - if ( ! $this->adapterConfig instanceof AbstractAdapter ) |
|
336 | + if ( ! $this->adapterConfig instanceof AbstractAdapter) |
|
337 | 337 | { |
338 | - $this->adapterConfig = $this->factoryConfig (); |
|
338 | + $this->adapterConfig = $this->factoryConfig(); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | return $this->adapterConfig; |
@@ -344,11 +344,11 @@ discard block |
||
344 | 344 | /** |
345 | 345 | * @return AdaptersDriver\AbsractAdapter |
346 | 346 | */ |
347 | - public function getAdapterDriver ( AdapterConfig\AbstractAdapter $config ) |
|
347 | + public function getAdapterDriver(AdapterConfig\AbstractAdapter $config) |
|
348 | 348 | { |
349 | - if ( ! $this->adapterDriver ) |
|
349 | + if ( ! $this->adapterDriver) |
|
350 | 350 | { |
351 | - $this->adapterDriver = $this->factoryDriver ( $config ); |
|
351 | + $this->adapterDriver = $this->factoryDriver($config); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | return $this->adapterDriver; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?= "<?php\n" ?> |
2 | -<?php $classNameModel = $objTables->getNamespace () . '_' . \Classes\Maker\AbstractMaker::getClassName ( $objTables->getName () ) ?> |
|
3 | -<?php $className = $objTables->getNamespace () . '_Entity_' . \Classes\Maker\AbstractMaker::getClassName ( |
|
4 | - $objTables->getName () |
|
2 | +<?php $classNameModel = $objTables->getNamespace() . '_' . \Classes\Maker\AbstractMaker::getClassName($objTables->getName()) ?> |
|
3 | +<?php $className = $objTables->getNamespace() . '_Entity_' . \Classes\Maker\AbstractMaker::getClassName( |
|
4 | + $objTables->getName() |
|
5 | 5 | ) ?> |
6 | 6 | |
7 | 7 | /** |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * |
10 | 10 | * <?= $this->config->last_modify . "\n" ?> |
11 | 11 | * |
12 | - * @package <?= $objTables->getNamespace () . "\n" ?> |
|
12 | + * @package <?= $objTables->getNamespace() . "\n" ?> |
|
13 | 13 | * @subpackage Entity |
14 | 14 | * |
15 | 15 | * @author <?= $this->config->author . "\n" ?> |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | */ |
26 | 26 | |
27 | 27 | abstract class <?= $className ?> extends <?= $this->config->namespace ? $this->config->namespace |
28 | - . "_" : "" ?>Model_<?= $objMakeFile->getParentClass ( |
|
28 | + . "_" : "" ?>Model_<?= $objMakeFile->getParentClass( |
|
29 | 29 | ) . "\n" ?> |
30 | 30 | { |
31 | 31 | |
32 | -<?php foreach ( $objTables->getColumns () as $column ): ?> |
|
32 | +<?php foreach ($objTables->getColumns() as $column): ?> |
|
33 | 33 | /** |
34 | - * Database constraint in the column <?= $column->getName () . "\n" ?> |
|
34 | + * Database constraint in the column <?= $column->getName() . "\n" ?> |
|
35 | 35 | * |
36 | 36 | */ |
37 | - const <?= strtoupper ( $column->getName () ) ?> = '<?= $objTables->getName () ?>.<?= $column->getName () ?>'; |
|
37 | + const <?= strtoupper($column->getName()) ?> = '<?= $objTables->getName() ?>.<?= $column->getName() ?>'; |
|
38 | 38 | <?php endforeach; ?> |
39 | 39 | |
40 | 40 | /** |
@@ -43,17 +43,17 @@ discard block |
||
43 | 43 | * @var string |
44 | 44 | * @access protected |
45 | 45 | */ |
46 | - protected $_tableClass = '<?= $objTables->getNamespace () ?>_DbTable_<?= \Classes\Maker\AbstractMaker::getClassName ( |
|
47 | - $objTables->getName () |
|
46 | + protected $_tableClass = '<?= $objTables->getNamespace() ?>_DbTable_<?= \Classes\Maker\AbstractMaker::getClassName( |
|
47 | + $objTables->getName() |
|
48 | 48 | ) ?>'; |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @see <?= $this->config->namespace ?>Model_EntityAbstract::$_columnsList |
52 | 52 | */ |
53 | 53 | protected $_columnsList = array( |
54 | -<?php foreach ( $objTables->getColumns () as $column ): ?> |
|
55 | - self::<?= strtoupper ( $column->getName () ) ?> => '<?= strtolower ( |
|
56 | - \Classes\Maker\AbstractMaker::getClassName ( $column->getName () ) |
|
54 | +<?php foreach ($objTables->getColumns() as $column): ?> |
|
55 | + self::<?= strtoupper($column->getName()) ?> => '<?= strtolower( |
|
56 | + \Classes\Maker\AbstractMaker::getClassName($column->getName()) |
|
57 | 57 | ) ?>', |
58 | 58 | <?php endforeach; ?> |
59 | 59 | ); |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | * @see <?= $this->config->namespace ?>Model_EntityAbstract::$_filters |
63 | 63 | */ |
64 | 64 | protected $_filters = array( |
65 | -<?php foreach ( $objTables->getColumns () as $column ): ?> |
|
65 | +<?php foreach ($objTables->getColumns() as $column): ?> |
|
66 | 66 | <?php |
67 | 67 | $filters = null; |
68 | - switch ( strtolower ( $column->getType () ) ) { |
|
68 | + switch (strtolower($column->getType())) { |
|
69 | 69 | case 'string': |
70 | 70 | $filters = 'StripTags", "StringTrim'; |
71 | 71 | break; |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | case 'boolean': |
78 | 78 | break; |
79 | 79 | default: |
80 | - $filters = ucfirst ( $column->getType () ); |
|
80 | + $filters = ucfirst($column->getType()); |
|
81 | 81 | break; |
82 | 82 | } |
83 | 83 | ?> |
84 | - '<?= $column->getName () ?>' => array ( |
|
85 | - <?= ( !empty( $filters ) ) ? "\"{$filters}\"\n" : null; ?> |
|
84 | + '<?= $column->getName() ?>' => array ( |
|
85 | + <?= ( ! empty($filters)) ? "\"{$filters}\"\n" : null; ?> |
|
86 | 86 | ), |
87 | 87 | <?php endforeach; ?> |
88 | 88 | ); |
@@ -91,34 +91,34 @@ discard block |
||
91 | 91 | * @see <?= $this->config->namespace ?>Model_EntityAbstract::$_validators |
92 | 92 | */ |
93 | 93 | protected $_validators= array( |
94 | -<?php foreach ( $objTables->getColumns () as $column ): ?> |
|
94 | +<?php foreach ($objTables->getColumns() as $column): ?> |
|
95 | 95 | <?php |
96 | - $validators = array (); |
|
96 | + $validators = array(); |
|
97 | 97 | |
98 | - $validators[] = $column->isNullable () ? "'allowEmpty' => true" : "'NotEmpty'"; |
|
98 | + $validators[] = $column->isNullable() ? "'allowEmpty' => true" : "'NotEmpty'"; |
|
99 | 99 | |
100 | - switch ( strtolower ( $column->getType () ) ) { |
|
100 | + switch (strtolower($column->getType())) { |
|
101 | 101 | case 'string': |
102 | - if ( $column->getMaxLength () ) { |
|
103 | - $validators[] = "array( 'StringLength', array( 'max' => " . $column->getMaxLength () . " ) )"; |
|
102 | + if ($column->getMaxLength()) { |
|
103 | + $validators[] = "array( 'StringLength', array( 'max' => " . $column->getMaxLength() . " ) )"; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | break; |
107 | 107 | case 'boolean': |
108 | 108 | break; |
109 | 109 | default: |
110 | - $name = ucfirst ( $column->getType () ); |
|
110 | + $name = ucfirst($column->getType()); |
|
111 | 111 | $validators[] = "'$name'"; |
112 | 112 | break; |
113 | 113 | } |
114 | -$validators = implode ( ", ", $validators ) ?> |
|
115 | - '<?= $column->getName () ?>' => array ( |
|
116 | - <?= ( !empty( $validators ) ) ? "{$validators}\n" : null ?> |
|
114 | +$validators = implode(", ", $validators) ?> |
|
115 | + '<?= $column->getName() ?>' => array ( |
|
116 | + <?= ( ! empty($validators)) ? "{$validators}\n" : null ?> |
|
117 | 117 | ), |
118 | 118 | <?php endforeach; ?> |
119 | 119 | ); |
120 | 120 | |
121 | -<?php if ( $objTables->hasPrimaryKey () ): ?> |
|
121 | +<?php if ($objTables->hasPrimaryKey()): ?> |
|
122 | 122 | /** |
123 | 123 | * Nome da Primary Key |
124 | 124 | * |
@@ -126,39 +126,39 @@ discard block |
||
126 | 126 | * @access protected |
127 | 127 | */ |
128 | 128 | protected $_primary = array( |
129 | -<?php foreach ( $objTables->getPrimarykeys () as $pks ) : ?> |
|
130 | - '<?= $pks->getName () ?>', |
|
129 | +<?php foreach ($objTables->getPrimarykeys() as $pks) : ?> |
|
130 | + '<?= $pks->getName() ?>', |
|
131 | 131 | <?php endforeach ?> |
132 | 132 | ); |
133 | 133 | <?php endif ?> |
134 | 134 | |
135 | -<?php foreach ( $parents as $parent ): ?> |
|
135 | +<?php foreach ($parents as $parent): ?> |
|
136 | 136 | /** |
137 | - * Parent relation <?= \Classes\Maker\AbstractMaker::getClassName ( $parent[ 'table' ] ) . "\n" ?> |
|
137 | + * Parent relation <?= \Classes\Maker\AbstractMaker::getClassName($parent['table']) . "\n" ?> |
|
138 | 138 | * |
139 | - * - CONSTRAINT in DB <?= $parent[ 'name' ] . "\n" ?> |
|
139 | + * - CONSTRAINT in DB <?= $parent['name'] . "\n" ?> |
|
140 | 140 | * |
141 | - * @var <?= $parent[ 'variable' ] . "\n" ?> |
|
141 | + * @var <?= $parent['variable'] . "\n" ?> |
|
142 | 142 | */ |
143 | - protected $_parent_<?= $parent[ 'variable' ] ?>; |
|
143 | + protected $_parent_<?= $parent['variable'] ?>; |
|
144 | 144 | |
145 | 145 | <?php endforeach; ?> |
146 | -<?php foreach ( $depends as $depend ): ?> |
|
146 | +<?php foreach ($depends as $depend): ?> |
|
147 | 147 | /** |
148 | - * Depends relation <?= \Classes\Maker\AbstractMaker::getClassName ( $depend[ 'table' ] ) . "\n" ?> |
|
148 | + * Depends relation <?= \Classes\Maker\AbstractMaker::getClassName($depend['table']) . "\n" ?> |
|
149 | 149 | * |
150 | - * - CONSTRAINT in DB <?= $depend[ 'name' ] . "\n" ?> |
|
150 | + * - CONSTRAINT in DB <?= $depend['name'] . "\n" ?> |
|
151 | 151 | * |
152 | - * @var <?= $depend[ 'variable' ] . "\n" ?> |
|
152 | + * @var <?= $depend['variable'] . "\n" ?> |
|
153 | 153 | */ |
154 | - protected $_depend_<?= $depend[ 'variable' ] ?>; |
|
154 | + protected $_depend_<?= $depend['variable'] ?>; |
|
155 | 155 | |
156 | 156 | <?php endforeach; ?> |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * @param int $primarykey |
160 | 160 | * |
161 | - * @return <?=$classNameModel."\n"?> |
|
161 | + * @return <?=$classNameModel . "\n"?> |
|
162 | 162 | */ |
163 | 163 | public function find ( $primarykey ) |
164 | 164 | { |
@@ -176,53 +176,53 @@ discard block |
||
176 | 176 | return <?=$classNameModel?>::retrieveAll ( $where , $order , $count , $offset ); |
177 | 177 | } |
178 | 178 | |
179 | -<?php foreach ( $objTables->getColumns () as $column ): ?> |
|
179 | +<?php foreach ($objTables->getColumns() as $column): ?> |
|
180 | 180 | /** |
181 | 181 | * |
182 | - * Sets column <?= $column->getName () . "\n" ?> |
|
182 | + * Sets column <?= $column->getName() . "\n" ?> |
|
183 | 183 | * |
184 | -<?php if ( $column->equalType ( 'date' ) ): ?> |
|
184 | +<?php if ($column->equalType('date')): ?> |
|
185 | 185 | * Stored in ISO 8601 format. |
186 | 186 | * |
187 | - * @param string|Zend_Date $<?= $column->getName () . "\n" ?> |
|
187 | + * @param string|Zend_Date $<?= $column->getName() . "\n" ?> |
|
188 | 188 | <?php else: ?> |
189 | - * @param <?= $column->getType () ?> $<?= $column->getName () . "\n" ?> |
|
189 | + * @param <?= $column->getType() ?> $<?= $column->getName() . "\n" ?> |
|
190 | 190 | <?php endif; ?> |
191 | 191 | * @return <?= $className . "\n" ?> |
192 | 192 | */ |
193 | - public function set<?= \Classes\Maker\AbstractMaker::getClassName ( $column->getName () ) ?>($<?= $column->getName ( |
|
193 | + public function set<?= \Classes\Maker\AbstractMaker::getClassName($column->getName()) ?>($<?= $column->getName( |
|
194 | 194 | ) ?>) |
195 | 195 | { |
196 | -<?php switch ( strtolower( $column->getType () ) ): |
|
196 | +<?php switch (strtolower($column->getType())): |
|
197 | 197 | case 'date': ?> |
198 | - if (! empty($<?= $column->getName () ?>)) |
|
198 | + if (! empty($<?= $column->getName() ?>)) |
|
199 | 199 | { |
200 | - if (! $<?= $column->getName () ?> instanceof Zend_Date) |
|
200 | + if (! $<?= $column->getName() ?> instanceof Zend_Date) |
|
201 | 201 | { |
202 | - $<?= $column->getName () ?> = new Zend_Date($<?= $column->getName () ?>); |
|
202 | + $<?= $column->getName() ?> = new Zend_Date($<?= $column->getName() ?>); |
|
203 | 203 | } |
204 | 204 | |
205 | - $this-><?= $column->getName () ?> = $<?= $column->getName () ?>->toString(Zend_Date::ISO_8601); |
|
205 | + $this-><?= $column->getName() ?> = $<?= $column->getName() ?>->toString(Zend_Date::ISO_8601); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | <?php break; |
209 | 209 | default: ?> |
210 | -<?php if(!$column->isNullable () && strtolower( $column->getType () ) != 'boolean'):?> |
|
211 | - $<?= $column->getName () ?> = (<?= ucfirst ( $column->getType () ) ?>) $<?= $column->getName () ?> ; |
|
210 | +<?php if ( ! $column->isNullable() && strtolower($column->getType()) != 'boolean'):?> |
|
211 | + $<?= $column->getName() ?> = (<?= ucfirst($column->getType()) ?>) $<?= $column->getName() ?> ; |
|
212 | 212 | <?php endif ?> |
213 | - $input = new Zend_Filter_Input($this->_filters, $this->_validators, array('<?= $column->getName ( |
|
214 | - ) ?>'=>$<?= $column->getName () ?> )); |
|
213 | + $input = new Zend_Filter_Input($this->_filters, $this->_validators, array('<?= $column->getName( |
|
214 | + ) ?>'=>$<?= $column->getName() ?> )); |
|
215 | 215 | |
216 | - if(!$input->isValid ('<?= $column->getName () ?>')) |
|
216 | + if(!$input->isValid ('<?= $column->getName() ?>')) |
|
217 | 217 | { |
218 | 218 | $errors = $input->getMessages (); |
219 | - foreach ( $errors['<?= $column->getName () ?>'] as $key => $value ) |
|
219 | + foreach ( $errors['<?= $column->getName() ?>'] as $key => $value ) |
|
220 | 220 | { |
221 | 221 | throw new Exception ( $value ); |
222 | 222 | } |
223 | 223 | } |
224 | 224 | |
225 | - $this-><?= $column->getName () ?> = $<?= $column->getName () ?> ; |
|
225 | + $this-><?= $column->getName() ?> = $<?= $column->getName() ?> ; |
|
226 | 226 | |
227 | 227 | <?php break ?> |
228 | 228 | <?php endswitch ?> |
@@ -230,71 +230,71 @@ discard block |
||
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
233 | - * Gets column <?= $column->getName () . "\n" ?> |
|
233 | + * Gets column <?= $column->getName() . "\n" ?> |
|
234 | 234 | * |
235 | -<?php if ( $column->equalType ( 'date' ) ): ?> |
|
235 | +<?php if ($column->equalType('date')): ?> |
|
236 | 236 | * @param boolean $returnZendDate |
237 | 237 | * @return Zend_Date|null|string Zend_Date representation of this datetime if enabled, or ISO 8601 string if not |
238 | 238 | <?php else: ?> |
239 | - * @return <?= $column->getType () . "\n" ?> |
|
239 | + * @return <?= $column->getType() . "\n" ?> |
|
240 | 240 | <?php endif; ?> |
241 | 241 | */ |
242 | - public function get<?= \Classes\Maker\AbstractMaker::getClassName ( |
|
243 | - $column->getName () |
|
244 | - ) ?>(<?php if ( $column->equalType ( 'date' ) ): ?>$returnZendDate = false <?php endif; ?>) |
|
242 | + public function get<?= \Classes\Maker\AbstractMaker::getClassName( |
|
243 | + $column->getName() |
|
244 | + ) ?>(<?php if ($column->equalType('date')): ?>$returnZendDate = false <?php endif; ?>) |
|
245 | 245 | { |
246 | -<?php if ( $column->equalType ( 'date' ) ): ?> |
|
246 | +<?php if ($column->equalType('date')): ?> |
|
247 | 247 | if ($returnZendDate) |
248 | 248 | { |
249 | - if ($this->_data['<?= $column->getName () ?>'] === null) |
|
249 | + if ($this->_data['<?= $column->getName() ?>'] === null) |
|
250 | 250 | { |
251 | 251 | return null; |
252 | 252 | } |
253 | 253 | |
254 | - return new Zend_Date($this-><?= $column->getName () ?>, Zend_Date::ISO_8601); |
|
254 | + return new Zend_Date($this-><?= $column->getName() ?>, Zend_Date::ISO_8601); |
|
255 | 255 | } |
256 | 256 | <?php endif; ?> |
257 | - return $this-><?= $column->getName () ?>; |
|
257 | + return $this-><?= $column->getName() ?>; |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | <?php endforeach; ?> |
261 | -<?php foreach ( $parents as $parent ): ?> |
|
261 | +<?php foreach ($parents as $parent): ?> |
|
262 | 262 | /** |
263 | - * Gets parent <?= $parent[ 'table' ] . "\n" ?> |
|
263 | + * Gets parent <?= $parent['table'] . "\n" ?> |
|
264 | 264 | * |
265 | - * @return <?= $parent[ 'class' ] . "\n" ?> |
|
265 | + * @return <?= $parent['class'] . "\n" ?> |
|
266 | 266 | */ |
267 | - public function get<?= $parent[ 'function' ] ?>() |
|
267 | + public function get<?= $parent['function'] ?>() |
|
268 | 268 | { |
269 | - if ($this->_parent_<?= $parent[ 'variable' ] ?> === null) |
|
269 | + if ($this->_parent_<?= $parent['variable'] ?> === null) |
|
270 | 270 | { |
271 | - $this->_parent_<?= $parent[ 'variable' ] ?> = $this->findParentRow('<?= $objTables->getNamespace ( |
|
272 | - ) ?>_DbTable_<?= \Classes\Maker\AbstractMaker::getClassName ( |
|
273 | - $parent[ 'table' ] |
|
274 | - ) ?>', '<?= \Classes\Maker\AbstractMaker::getClassName ( $parent[ 'variable' ] ) ?>'); |
|
271 | + $this->_parent_<?= $parent['variable'] ?> = $this->findParentRow('<?= $objTables->getNamespace( |
|
272 | + ) ?>_DbTable_<?= \Classes\Maker\AbstractMaker::getClassName( |
|
273 | + $parent['table'] |
|
274 | + ) ?>', '<?= \Classes\Maker\AbstractMaker::getClassName($parent['variable']) ?>'); |
|
275 | 275 | } |
276 | 276 | |
277 | - return $this->_parent_<?= $parent[ 'variable' ] ?>; |
|
277 | + return $this->_parent_<?= $parent['variable'] ?>; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | <?php endforeach; ?> |
281 | 281 | |
282 | 282 | |
283 | -<?php foreach ( $depends as $depend ): ?> |
|
283 | +<?php foreach ($depends as $depend): ?> |
|
284 | 284 | /** |
285 | - * Gets dependent <?= $depend[ 'table' ] . "\n" ?> |
|
285 | + * Gets dependent <?= $depend['table'] . "\n" ?> |
|
286 | 286 | * |
287 | - * @return <?= $depend[ 'class' ] . "\n" ?> |
|
287 | + * @return <?= $depend['class'] . "\n" ?> |
|
288 | 288 | */ |
289 | - public function get<?= $depend[ 'function' ] ?>() |
|
289 | + public function get<?= $depend['function'] ?>() |
|
290 | 290 | { |
291 | - if ($this->_depend_<?= $depend[ 'variable' ] ?> === null) |
|
291 | + if ($this->_depend_<?= $depend['variable'] ?> === null) |
|
292 | 292 | { |
293 | - $this->_depend_<?= $depend[ 'variable' ] ?> = $this->findDependentRowset('<?= $objTables->getNamespace ( |
|
294 | - ) ?>_DbTable_<?= \Classes\Maker\AbstractMaker::getClassName ( $depend[ 'table' ] ) ?>'); |
|
293 | + $this->_depend_<?= $depend['variable'] ?> = $this->findDependentRowset('<?= $objTables->getNamespace( |
|
294 | + ) ?>_DbTable_<?= \Classes\Maker\AbstractMaker::getClassName($depend['table']) ?>'); |
|
295 | 295 | } |
296 | 296 | |
297 | - return $this->_depend_<?= $depend[ 'variable' ] ?>; |
|
297 | + return $this->_depend_<?= $depend['variable'] ?>; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | <?php endforeach; ?> |
@@ -115,32 +115,32 @@ discard block |
||
115 | 115 | if ( $table->hasColumn ( $constrant[ "column_name" ] ) ) |
116 | 116 | { |
117 | 117 | $objConstrant = Constrant::getInstance () |
118 | - ->populate ( |
|
119 | - array ( |
|
120 | - 'constrant' => $constrant[ 'constraint_name' ] , |
|
121 | - 'schema' => $constrant[ 'foreign_schema' ] , |
|
122 | - 'table' => $constrant[ 'foreign_table' ] , |
|
123 | - 'column' => $constrant[ 'foreign_column' ] , |
|
124 | - 'database' => $this->database |
|
125 | - ) |
|
126 | - ); |
|
118 | + ->populate ( |
|
119 | + array ( |
|
120 | + 'constrant' => $constrant[ 'constraint_name' ] , |
|
121 | + 'schema' => $constrant[ 'foreign_schema' ] , |
|
122 | + 'table' => $constrant[ 'foreign_table' ] , |
|
123 | + 'column' => $constrant[ 'foreign_column' ] , |
|
124 | + 'database' => $this->database |
|
125 | + ) |
|
126 | + ); |
|
127 | 127 | |
128 | 128 | switch ( $constrant[ 'constraint_type' ] ) |
129 | 129 | { |
130 | 130 | case "FOREIGN KEY": |
131 | 131 | $table->getColumn ( $constrant[ "column_name" ] ) |
132 | - ->addRefFk ( $objConstrant ); |
|
132 | + ->addRefFk ( $objConstrant ); |
|
133 | 133 | break; |
134 | 134 | case"PRIMARY KEY": |
135 | 135 | $table->getColumn ( $constrant[ "column_name" ] ) |
136 | - ->setPrimaryKey ( $objConstrant ) |
|
137 | - ->setSequence ( |
|
138 | - $this->getSequence ( |
|
139 | - $table_name , |
|
140 | - $constrant[ "column_name" ] , |
|
141 | - $schema |
|
142 | - ) |
|
143 | - ); |
|
136 | + ->setPrimaryKey ( $objConstrant ) |
|
137 | + ->setSequence ( |
|
138 | + $this->getSequence ( |
|
139 | + $table_name , |
|
140 | + $constrant[ "column_name" ] , |
|
141 | + $schema |
|
142 | + ) |
|
143 | + ); |
|
144 | 144 | break; |
145 | 145 | } |
146 | 146 | } |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | if ( $table->hasColumn ( $constrant[ "foreign_column" ] ) ) |
161 | 161 | { |
162 | 162 | $table->getColumn ( $constrant[ "foreign_column" ] ) |
163 | - ->createDependece ( |
|
164 | - $constrant[ 'constraint_name' ] , |
|
165 | - $constrant[ 'table_name' ] , |
|
166 | - $constrant[ 'column_name' ] , |
|
167 | - $this->database , |
|
168 | - $constrant[ 'table_schema' ] |
|
169 | - ); |
|
163 | + ->createDependece ( |
|
164 | + $constrant[ 'constraint_name' ] , |
|
165 | + $constrant[ 'table_name' ] , |
|
166 | + $constrant[ 'column_name' ] , |
|
167 | + $this->database , |
|
168 | + $constrant[ 'table_schema' ] |
|
169 | + ); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | } |
@@ -201,10 +201,10 @@ discard block |
||
201 | 201 | ); |
202 | 202 | |
203 | 203 | $this->getTable ( $key , $schema ) |
204 | - ->addColumn ( $column ) |
|
205 | - ->setNamespace ( |
|
206 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
207 | - ); |
|
204 | + ->addColumn ( $column ) |
|
205 | + ->setNamespace ( |
|
206 | + $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
207 | + ); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
@@ -279,13 +279,13 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | $this->objDbTables[ $schema ][ trim ( $nameTable ) ] = DbTable::getInstance () |
282 | - ->populate ( |
|
283 | - array ( |
|
284 | - 'table' => $nameTable , |
|
285 | - 'schema' => $schema , |
|
286 | - 'database' => $this->database |
|
287 | - ) |
|
288 | - ); |
|
282 | + ->populate ( |
|
283 | + array ( |
|
284 | + 'table' => $nameTable , |
|
285 | + 'schema' => $schema , |
|
286 | + 'database' => $this->database |
|
287 | + ) |
|
288 | + ); |
|
289 | 289 | |
290 | 290 | return $this; |
291 | 291 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | /** |
68 | 68 | * @type \Classes\Db\Iterators\DbTables[] |
69 | 69 | */ |
70 | - private $objDbTables = array (); |
|
70 | + private $objDbTables = array(); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @var AbstractAdapter |
@@ -82,22 +82,22 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * analisa e popula as Foreing keys, Primary keys e dependencias do banco nos objetos |
84 | 84 | */ |
85 | - protected function parseConstrants () |
|
85 | + protected function parseConstrants() |
|
86 | 86 | { |
87 | - foreach ( $this->getListConstrant () as $constrant ) |
|
87 | + foreach ($this->getListConstrant() as $constrant) |
|
88 | 88 | { |
89 | 89 | |
90 | - $schema = $constrant[ 'table_schema' ]; |
|
91 | - $table_name = $constrant [ 'table_name' ]; |
|
92 | - $this->populateForeignAndPrimaryKeys ( $constrant , $table_name , $schema ); |
|
93 | - unset( $table_name , $schema ); |
|
90 | + $schema = $constrant['table_schema']; |
|
91 | + $table_name = $constrant ['table_name']; |
|
92 | + $this->populateForeignAndPrimaryKeys($constrant, $table_name, $schema); |
|
93 | + unset($table_name, $schema); |
|
94 | 94 | |
95 | - if ( $constrant[ 'constraint_type' ] == "FOREIGN KEY" ) |
|
95 | + if ($constrant['constraint_type'] == "FOREIGN KEY") |
|
96 | 96 | { |
97 | - $schema = $constrant[ 'foreign_schema' ]; |
|
98 | - $table_name = $constrant [ 'foreign_table' ]; |
|
99 | - $this->populateDependece ( $constrant , $table_name , $schema ); |
|
100 | - unset( $table_name , $schema ); |
|
97 | + $schema = $constrant['foreign_schema']; |
|
98 | + $table_name = $constrant ['foreign_table']; |
|
99 | + $this->populateDependece($constrant, $table_name, $schema); |
|
100 | + unset($table_name, $schema); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | } |
@@ -107,37 +107,37 @@ discard block |
||
107 | 107 | * @param string $table_name |
108 | 108 | * @param int $schema |
109 | 109 | */ |
110 | - private function populateForeignAndPrimaryKeys ( $constrant , $table_name , $schema = 0 ) |
|
110 | + private function populateForeignAndPrimaryKeys($constrant, $table_name, $schema = 0) |
|
111 | 111 | { |
112 | - if ( $this->hasTable ( $table_name , $schema ) ) |
|
112 | + if ($this->hasTable($table_name, $schema)) |
|
113 | 113 | { |
114 | - $table = $this->getTable ( $table_name , $schema ); |
|
115 | - if ( $table->hasColumn ( $constrant[ "column_name" ] ) ) |
|
114 | + $table = $this->getTable($table_name, $schema); |
|
115 | + if ($table->hasColumn($constrant["column_name"])) |
|
116 | 116 | { |
117 | - $objConstrant = Constrant::getInstance () |
|
118 | - ->populate ( |
|
119 | - array ( |
|
120 | - 'constrant' => $constrant[ 'constraint_name' ] , |
|
121 | - 'schema' => $constrant[ 'foreign_schema' ] , |
|
122 | - 'table' => $constrant[ 'foreign_table' ] , |
|
123 | - 'column' => $constrant[ 'foreign_column' ] , |
|
117 | + $objConstrant = Constrant::getInstance() |
|
118 | + ->populate( |
|
119 | + array( |
|
120 | + 'constrant' => $constrant['constraint_name'], |
|
121 | + 'schema' => $constrant['foreign_schema'], |
|
122 | + 'table' => $constrant['foreign_table'], |
|
123 | + 'column' => $constrant['foreign_column'], |
|
124 | 124 | 'database' => $this->database |
125 | 125 | ) |
126 | 126 | ); |
127 | 127 | |
128 | - switch ( $constrant[ 'constraint_type' ] ) |
|
128 | + switch ($constrant['constraint_type']) |
|
129 | 129 | { |
130 | 130 | case "FOREIGN KEY": |
131 | - $table->getColumn ( $constrant[ "column_name" ] ) |
|
132 | - ->addRefFk ( $objConstrant ); |
|
131 | + $table->getColumn($constrant["column_name"]) |
|
132 | + ->addRefFk($objConstrant); |
|
133 | 133 | break; |
134 | 134 | case"PRIMARY KEY": |
135 | - $table->getColumn ( $constrant[ "column_name" ] ) |
|
136 | - ->setPrimaryKey ( $objConstrant ) |
|
137 | - ->setSequence ( |
|
138 | - $this->getSequence ( |
|
139 | - $table_name , |
|
140 | - $constrant[ "column_name" ] , |
|
135 | + $table->getColumn($constrant["column_name"]) |
|
136 | + ->setPrimaryKey($objConstrant) |
|
137 | + ->setSequence( |
|
138 | + $this->getSequence( |
|
139 | + $table_name, |
|
140 | + $constrant["column_name"], |
|
141 | 141 | $schema |
142 | 142 | ) |
143 | 143 | ); |
@@ -152,20 +152,20 @@ discard block |
||
152 | 152 | * @param string $table_name |
153 | 153 | * @param int $schema |
154 | 154 | */ |
155 | - private function populateDependece ( $constrant , $table_name , $schema = 0 ) |
|
155 | + private function populateDependece($constrant, $table_name, $schema = 0) |
|
156 | 156 | { |
157 | - if ( $this->hasTable ( $table_name , $schema ) ) |
|
157 | + if ($this->hasTable($table_name, $schema)) |
|
158 | 158 | { |
159 | - $table = $this->getTable ( $table_name , $schema ); |
|
160 | - if ( $table->hasColumn ( $constrant[ "foreign_column" ] ) ) |
|
159 | + $table = $this->getTable($table_name, $schema); |
|
160 | + if ($table->hasColumn($constrant["foreign_column"])) |
|
161 | 161 | { |
162 | - $table->getColumn ( $constrant[ "foreign_column" ] ) |
|
163 | - ->createDependece ( |
|
164 | - $constrant[ 'constraint_name' ] , |
|
165 | - $constrant[ 'table_name' ] , |
|
166 | - $constrant[ 'column_name' ] , |
|
167 | - $this->database , |
|
168 | - $constrant[ 'table_schema' ] |
|
162 | + $table->getColumn($constrant["foreign_column"]) |
|
163 | + ->createDependece( |
|
164 | + $constrant['constraint_name'], |
|
165 | + $constrant['table_name'], |
|
166 | + $constrant['column_name'], |
|
167 | + $this->database, |
|
168 | + $constrant['table_schema'] |
|
169 | 169 | ); |
170 | 170 | } |
171 | 171 | } |
@@ -174,36 +174,36 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * cria um Array com nome das tabelas |
176 | 176 | */ |
177 | - public function parseTables () |
|
177 | + public function parseTables() |
|
178 | 178 | { |
179 | - if ( $this->hasTables () ) |
|
179 | + if ($this->hasTables()) |
|
180 | 180 | { |
181 | - return $this->getAllTables (); |
|
181 | + return $this->getAllTables(); |
|
182 | 182 | } |
183 | 183 | |
184 | - foreach ( $this->getListColumns () as $table ) |
|
184 | + foreach ($this->getListColumns() as $table) |
|
185 | 185 | { |
186 | - $schema = $table[ 'table_schema' ]; |
|
187 | - $key = $table [ 'table_name' ]; |
|
188 | - if ( ! $this->hasTable ( $key , $schema ) ) |
|
186 | + $schema = $table['table_schema']; |
|
187 | + $key = $table ['table_name']; |
|
188 | + if ( ! $this->hasTable($key, $schema)) |
|
189 | 189 | { |
190 | - $this->createTable ( $key , $schema ); |
|
190 | + $this->createTable($key, $schema); |
|
191 | 191 | } |
192 | 192 | |
193 | - $column = Column::getInstance () |
|
194 | - ->populate ( |
|
195 | - array ( |
|
196 | - 'name' => $table [ 'column_name' ] , |
|
197 | - 'type' => $this->convertTypeToSimple ( $table[ 'data_type' ] ) , |
|
198 | - 'nullable' => (is_string($table[ 'is_nullable' ]) && strtolower($table[ 'is_nullable' ]) != 'no' ) , |
|
199 | - 'max_length' => $table[ 'max_length' ] |
|
193 | + $column = Column::getInstance() |
|
194 | + ->populate( |
|
195 | + array( |
|
196 | + 'name' => $table ['column_name'], |
|
197 | + 'type' => $this->convertTypeToSimple($table['data_type']), |
|
198 | + 'nullable' => (is_string($table['is_nullable']) && strtolower($table['is_nullable']) != 'no'), |
|
199 | + 'max_length' => $table['max_length'] |
|
200 | 200 | ) |
201 | 201 | ); |
202 | 202 | |
203 | - $this->getTable ( $key , $schema ) |
|
204 | - ->addColumn ( $column ) |
|
205 | - ->setNamespace ( |
|
206 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
203 | + $this->getTable($key, $schema) |
|
204 | + ->addColumn($column) |
|
205 | + ->setNamespace( |
|
206 | + $this->config->createClassNamespace($this->getTable($key, $schema)) |
|
207 | 207 | ); |
208 | 208 | } |
209 | 209 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @return int |
215 | 215 | */ |
216 | - abstract public function getTotalTables (); |
|
216 | + abstract public function getTotalTables(); |
|
217 | 217 | |
218 | 218 | /** |
219 | 219 | * Retorna o Nome da Sequence da tabela |
@@ -223,33 +223,33 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return string |
225 | 225 | */ |
226 | - abstract public function getSequence ( $table , $column , $schema = 0 ); |
|
226 | + abstract public function getSequence($table, $column, $schema = 0); |
|
227 | 227 | |
228 | 228 | /** |
229 | 229 | * @return array |
230 | 230 | */ |
231 | - abstract public function getListConstrant (); |
|
231 | + abstract public function getListConstrant(); |
|
232 | 232 | |
233 | 233 | /** |
234 | 234 | * @param string $str |
235 | 235 | * |
236 | 236 | * @return string |
237 | 237 | */ |
238 | - protected function convertTypeToPhp ( $str ) |
|
238 | + protected function convertTypeToPhp($str) |
|
239 | 239 | { |
240 | - if ( isset( $this->dataTypesToPhp[ $str ] ) ) |
|
240 | + if (isset($this->dataTypesToPhp[$str])) |
|
241 | 241 | { |
242 | - return $this->dataTypesToPhp[ $str ]; |
|
242 | + return $this->dataTypesToPhp[$str]; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | return 'string'; |
246 | 246 | } |
247 | 247 | |
248 | - protected function convertTypeToSimple ( $str ) |
|
248 | + protected function convertTypeToSimple($str) |
|
249 | 249 | { |
250 | - if ( isset( $this->dataTypesToSimple[ $str ] ) ) |
|
250 | + if (isset($this->dataTypesToSimple[$str])) |
|
251 | 251 | { |
252 | - return $this->dataTypesToSimple[ $str ]; |
|
252 | + return $this->dataTypesToSimple[$str]; |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | return 'string'; |
@@ -258,12 +258,12 @@ discard block |
||
258 | 258 | /** |
259 | 259 | * @return string |
260 | 260 | */ |
261 | - abstract public function getPDOString (); |
|
261 | + abstract public function getPDOString(); |
|
262 | 262 | |
263 | 263 | /** |
264 | 264 | * @return string |
265 | 265 | */ |
266 | - abstract public function getPDOSocketString (); |
|
266 | + abstract public function getPDOSocketString(); |
|
267 | 267 | |
268 | 268 | /** |
269 | 269 | * @param $nameTable |
@@ -271,18 +271,18 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @return \Classes\Db\DbTable |
273 | 273 | */ |
274 | - public function createTable ( $nameTable , $schema = 0 ) |
|
274 | + public function createTable($nameTable, $schema = 0) |
|
275 | 275 | { |
276 | - if ( ! isset( $this->objDbTables[ $schema ] ) ) |
|
276 | + if ( ! isset($this->objDbTables[$schema])) |
|
277 | 277 | { |
278 | - $this->objDbTables[ $schema ] = new DbTables(); |
|
278 | + $this->objDbTables[$schema] = new DbTables(); |
|
279 | 279 | } |
280 | 280 | |
281 | - $this->objDbTables[ $schema ][ trim ( $nameTable ) ] = DbTable::getInstance () |
|
282 | - ->populate ( |
|
283 | - array ( |
|
284 | - 'table' => $nameTable , |
|
285 | - 'schema' => $schema , |
|
281 | + $this->objDbTables[$schema][trim($nameTable)] = DbTable::getInstance() |
|
282 | + ->populate( |
|
283 | + array( |
|
284 | + 'table' => $nameTable, |
|
285 | + 'schema' => $schema, |
|
286 | 286 | 'database' => $this->database |
287 | 287 | ) |
288 | 288 | ); |
@@ -295,24 +295,24 @@ discard block |
||
295 | 295 | * |
296 | 296 | * @return \Classes\Db\Iterators\DbTables |
297 | 297 | */ |
298 | - public function getTables ( $schema = 0 ) |
|
298 | + public function getTables($schema = 0) |
|
299 | 299 | { |
300 | - if ( ! isset( $this->objDbTables[ $schema ] ) ) |
|
300 | + if ( ! isset($this->objDbTables[$schema])) |
|
301 | 301 | { |
302 | - return array (); |
|
302 | + return array(); |
|
303 | 303 | } |
304 | 304 | |
305 | - return $this->objDbTables[ $schema ]; |
|
305 | + return $this->objDbTables[$schema]; |
|
306 | 306 | } |
307 | 307 | |
308 | - public function getAllTables () |
|
308 | + public function getAllTables() |
|
309 | 309 | { |
310 | 310 | return $this->objDbTables; |
311 | 311 | } |
312 | 312 | |
313 | - public function hasTables () |
|
313 | + public function hasTables() |
|
314 | 314 | { |
315 | - return ! empty( $this->objDbTables ); |
|
315 | + return ! empty($this->objDbTables); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -322,9 +322,9 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @return \Classes\Db\DbTable |
324 | 324 | */ |
325 | - public function getTable ( $nameTable , $schema = 0 ) |
|
325 | + public function getTable($nameTable, $schema = 0) |
|
326 | 326 | { |
327 | - return $this->objDbTables[ $schema ][ trim ( $nameTable ) ]; |
|
327 | + return $this->objDbTables[$schema][trim($nameTable)]; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -333,9 +333,9 @@ discard block |
||
333 | 333 | * |
334 | 334 | * @return bool |
335 | 335 | */ |
336 | - public function hasTable ( $nameTable , $schema = 0 ) |
|
336 | + public function hasTable($nameTable, $schema = 0) |
|
337 | 337 | { |
338 | - return isset( $this->objDbTables[ $schema ][ trim ( $nameTable ) ] ); |
|
338 | + return isset($this->objDbTables[$schema][trim($nameTable)]); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -343,66 +343,66 @@ discard block |
||
343 | 343 | * |
344 | 344 | * @return array[] |
345 | 345 | */ |
346 | - abstract public function getListColumns (); |
|
346 | + abstract public function getListColumns(); |
|
347 | 347 | |
348 | 348 | /** |
349 | 349 | * Retorna um Array com nome das tabelas |
350 | 350 | * |
351 | 351 | * @return string[] |
352 | 352 | */ |
353 | - abstract public function getListNameTable (); |
|
353 | + abstract public function getListNameTable(); |
|
354 | 354 | |
355 | 355 | /** |
356 | 356 | * @param \Classes\AdapterConfig\AbstractAdapter $adapterConfig |
357 | 357 | */ |
358 | - public function __construct ( AbstractAdapter $adapterConfig ) |
|
358 | + public function __construct(AbstractAdapter $adapterConfig) |
|
359 | 359 | { |
360 | 360 | $this->config = $adapterConfig; |
361 | - $this->host = $adapterConfig->getHost (); |
|
362 | - $this->database = $adapterConfig->getDatabase (); |
|
363 | - $this->port = $adapterConfig->hasPort () ? $adapterConfig->getPort () |
|
361 | + $this->host = $adapterConfig->getHost(); |
|
362 | + $this->database = $adapterConfig->getDatabase(); |
|
363 | + $this->port = $adapterConfig->hasPort() ? $adapterConfig->getPort() |
|
364 | 364 | : $this->port; |
365 | - $this->username = $adapterConfig->getUser (); |
|
366 | - $this->password = $adapterConfig->getPassword (); |
|
367 | - $this->socket = $adapterConfig->getSocket (); |
|
368 | - $this->tablesName = $adapterConfig->hasTablesName () |
|
369 | - ? $adapterConfig->getListTablesName () : ''; |
|
365 | + $this->username = $adapterConfig->getUser(); |
|
366 | + $this->password = $adapterConfig->getPassword(); |
|
367 | + $this->socket = $adapterConfig->getSocket(); |
|
368 | + $this->tablesName = $adapterConfig->hasTablesName() |
|
369 | + ? $adapterConfig->getListTablesName() : ''; |
|
370 | 370 | |
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
374 | 374 | * Executa as consultas do banco de dados |
375 | 375 | */ |
376 | - public function runDatabase () |
|
376 | + public function runDatabase() |
|
377 | 377 | { |
378 | - $this->parseTables (); |
|
379 | - $this->parseConstrants (); |
|
378 | + $this->parseTables(); |
|
379 | + $this->parseConstrants(); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
383 | 383 | * |
384 | 384 | * @return \PDO |
385 | 385 | */ |
386 | - public function getPDO () |
|
386 | + public function getPDO() |
|
387 | 387 | { |
388 | - if ( is_null ( $this->_pdo ) ) |
|
388 | + if (is_null($this->_pdo)) |
|
389 | 389 | { |
390 | - if ( ! empty( $this->socket ) ) |
|
390 | + if ( ! empty($this->socket)) |
|
391 | 391 | { |
392 | - $pdoString = $this->getPDOSocketString (); |
|
392 | + $pdoString = $this->getPDOSocketString(); |
|
393 | 393 | } else |
394 | 394 | { |
395 | - $pdoString = $this->getPDOString (); |
|
395 | + $pdoString = $this->getPDOString(); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | try |
399 | 399 | { |
400 | - $this->_pdo = new \PDO ( |
|
401 | - $pdoString , $this->username , $this->password |
|
400 | + $this->_pdo = new \PDO( |
|
401 | + $pdoString, $this->username, $this->password |
|
402 | 402 | ); |
403 | - } catch ( \Exception $e ) |
|
403 | + } catch (\Exception $e) |
|
404 | 404 | { |
405 | - die ( "\033[0;31mPDO error: " . $e->getMessage () . "\033[0m\n" ); |
|
405 | + die ("\033[0;31mPDO error: " . $e->getMessage() . "\033[0m\n"); |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 |