@@ -13,28 +13,28 @@ discard block |
||
13 | 13 | class GitHub extends AbstractContent |
14 | 14 | { |
15 | 15 | private static $tagsGithub = "https://api.github.com/repos/pedro151/orm-generator/tags"; |
16 | - private static $listVersion = array (); |
|
16 | + private static $listVersion = array(); |
|
17 | 17 | private $phar = "https://raw.githubusercontent.com/pedro151/orm-generator/%s/bin/orm-generator.phar"; |
18 | 18 | //private $phar = "https://github.com/pedro151/orm-generator/blob/%s/bin/orm-generator.phar?raw=true"; |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @return mixed |
22 | 22 | */ |
23 | - public function getInfo () |
|
23 | + public function getInfo() |
|
24 | 24 | { |
25 | - return json_decode ( $this->getContent ( self::$tagsGithub ) ); |
|
25 | + return json_decode($this->getContent(self::$tagsGithub)); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
29 | 29 | * |
30 | 30 | */ |
31 | - protected function init () |
|
31 | + protected function init() |
|
32 | 32 | { |
33 | - if ( is_array ( $this->getInfo () ) ) |
|
33 | + if (is_array($this->getInfo())) |
|
34 | 34 | { |
35 | - foreach ( $this->getInfo () as $index => $objTag ) |
|
35 | + foreach ($this->getInfo() as $index => $objTag) |
|
36 | 36 | { |
37 | - self::$listVersion[ preg_replace ( "/[^0-9.]/" , "" , $objTag->name ) ] = sprintf ( $this->phar , $objTag->name ); |
|
37 | + self::$listVersion[preg_replace("/[^0-9.]/", "", $objTag->name)] = sprintf($this->phar, $objTag->name); |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 | } |
@@ -42,19 +42,19 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @return mixed |
44 | 44 | */ |
45 | - public function getLastVersion () |
|
45 | + public function getLastVersion() |
|
46 | 46 | { |
47 | - return current ( array_keys ( self::$listVersion ) ); |
|
47 | + return current(array_keys(self::$listVersion)); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @return mixed |
52 | 52 | */ |
53 | - public function getLastPhar () |
|
53 | + public function getLastPhar() |
|
54 | 54 | { |
55 | - reset ( self::$listVersion ); |
|
55 | + reset(self::$listVersion); |
|
56 | 56 | |
57 | - return current ( self::$listVersion ); |
|
57 | + return current(self::$listVersion); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return mixed |
64 | 64 | */ |
65 | - public function getPharByVersion ( $version ) |
|
65 | + public function getPharByVersion($version) |
|
66 | 66 | { |
67 | - return self::$listVersion[ $version ]; |
|
67 | + return self::$listVersion[$version]; |
|
68 | 68 | } |
69 | 69 | |
70 | - public function hasPharByVersion ( $version ) |
|
70 | + public function hasPharByVersion($version) |
|
71 | 71 | { |
72 | - return isset( self::$listVersion[ $version ] ); |
|
72 | + return isset(self::$listVersion[$version]); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | } |
76 | 76 | \ No newline at end of file |
@@ -38,7 +38,7 @@ |
||
38 | 38 | if ( self::HasNewVersion () ) |
39 | 39 | { |
40 | 40 | return "\033[0;31mThere is a new version " . self::$lastVersion |
41 | - . " available\033[0m \n"; |
|
41 | + . " available\033[0m \n"; |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @return string |
17 | 17 | */ |
18 | - public static function getVersion () |
|
18 | + public static function getVersion() |
|
19 | 19 | { |
20 | 20 | return static::$_currentVersion; |
21 | 21 | } |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @return bool |
25 | 25 | */ |
26 | - public static function HasNewVersion () |
|
26 | + public static function HasNewVersion() |
|
27 | 27 | { |
28 | - self::$lastVersion = GitHub::getInstance ()->getLastVersion (); |
|
28 | + self::$lastVersion = GitHub::getInstance()->getLastVersion(); |
|
29 | 29 | |
30 | 30 | return self::$lastVersion > static::$_currentVersion; |
31 | 31 | } |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * @return string |
35 | 35 | */ |
36 | - public function messageHasNewVersion () |
|
36 | + public function messageHasNewVersion() |
|
37 | 37 | { |
38 | - if ( self::HasNewVersion () ) |
|
38 | + if (self::HasNewVersion()) |
|
39 | 39 | { |
40 | 40 | return "\033[0;31mThere is a new version " . self::$lastVersion |
41 | 41 | . " available\033[0m \n"; |
@@ -47,14 +47,14 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return bool |
49 | 49 | */ |
50 | - public static function equalVersion ( $version ) |
|
50 | + public static function equalVersion($version) |
|
51 | 51 | { |
52 | - return $version === self::getVersion (); |
|
52 | + return $version === self::getVersion(); |
|
53 | 53 | } |
54 | 54 | |
55 | - public static function existVersion ( $version ) |
|
55 | + public static function existVersion($version) |
|
56 | 56 | { |
57 | - return GitHub::getInstance ()->hasPharByVersion ( $version ); |
|
57 | + return GitHub::getInstance()->hasPharByVersion($version); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | } |
61 | 61 | \ No newline at end of file |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | foreach ( $arrFoldersName as $index => $folderName ) |
101 | 101 | { |
102 | 102 | $arrFoldersName[ $index ] = $this->getConfig () |
103 | - ->replaceReservedWord ( $folderName ); |
|
103 | + ->replaceReservedWord ( $folderName ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | return implode ( DIRECTORY_SEPARATOR , array_filter ( $arrFoldersName ) ); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $folderName , |
158 | 158 | $this->getClassName ( |
159 | 159 | $this->getConfig () |
160 | - ->getDatabase () |
|
160 | + ->getDatabase () |
|
161 | 161 | ) |
162 | 162 | ); |
163 | 163 | $this->location = array ( $this->filterLocation ( $url ) ); |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @type string[] |
24 | 24 | */ |
25 | - public $location = array (); |
|
25 | + public $location = array(); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * caminho de pastas Base |
@@ -46,46 +46,46 @@ discard block |
||
46 | 46 | |
47 | 47 | private $msgReservedWord = "\033[0mPlease enter the value for reserved word \033[0;31m'%index%' \033[1;33m[%config%]:\033[0m "; |
48 | 48 | |
49 | - public function __construct ( Config $config ) |
|
49 | + public function __construct(Config $config) |
|
50 | 50 | { |
51 | - $this->config = $config->getAdapterConfig (); |
|
52 | - $this->parseReservedWord ( $this->getConfig () ); |
|
53 | - $this->driver = $config->getAdapterDriver ( $this->getConfig () ); |
|
54 | - $this->parseLocation ( $config->_basePath ); |
|
51 | + $this->config = $config->getAdapterConfig(); |
|
52 | + $this->parseReservedWord($this->getConfig()); |
|
53 | + $this->driver = $config->getAdapterDriver($this->getConfig()); |
|
54 | + $this->parseLocation($config->_basePath); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @param AdapterConfig\AbstractAdapter $config |
59 | 59 | */ |
60 | - public function parseReservedWord ( AdapterConfig\AbstractAdapter $config ) |
|
60 | + public function parseReservedWord(AdapterConfig\AbstractAdapter $config) |
|
61 | 61 | { |
62 | 62 | $palavrasReservadas = $config->reservedWord; |
63 | - if ( ! $palavrasReservadas ) |
|
63 | + if ( ! $palavrasReservadas) |
|
64 | 64 | { |
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
68 | - $schema = $config->getSchemas (); |
|
69 | - $db = $config->getDatabase (); |
|
70 | - $hasSchema = array_intersect ( $schema , array_flip ( $palavrasReservadas ) ); |
|
71 | - $hasDatabase = in_array ( $db , $palavrasReservadas ); |
|
72 | - if ( ! ( $hasSchema or $hasDatabase ) ) |
|
68 | + $schema = $config->getSchemas(); |
|
69 | + $db = $config->getDatabase(); |
|
70 | + $hasSchema = array_intersect($schema, array_flip($palavrasReservadas)); |
|
71 | + $hasDatabase = in_array($db, $palavrasReservadas); |
|
72 | + if ( ! ($hasSchema or $hasDatabase)) |
|
73 | 73 | { |
74 | 74 | return; |
75 | 75 | } |
76 | 76 | |
77 | 77 | echo "- database has reserved words\n"; |
78 | - foreach ( $palavrasReservadas as $index => $config ) |
|
78 | + foreach ($palavrasReservadas as $index => $config) |
|
79 | 79 | { |
80 | - $attribs = array ( |
|
81 | - "%index%" => $index , |
|
80 | + $attribs = array( |
|
81 | + "%index%" => $index, |
|
82 | 82 | "%config%" => $config |
83 | 83 | ); |
84 | - echo strtr ( $this->msgReservedWord , $attribs ); |
|
85 | - $line = trim ( fgets ( STDIN ) ); |
|
86 | - if ( ! empty( $line ) ) |
|
84 | + echo strtr($this->msgReservedWord, $attribs); |
|
85 | + $line = trim(fgets(STDIN)); |
|
86 | + if ( ! empty($line)) |
|
87 | 87 | { |
88 | - $this->getConfig ()->reservedWord[ $index ] = $line; |
|
88 | + $this->getConfig()->reservedWord[$index] = $line; |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
@@ -95,199 +95,199 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return string |
97 | 97 | */ |
98 | - private function filterLocation ( $arrFoldersName ) |
|
98 | + private function filterLocation($arrFoldersName) |
|
99 | 99 | { |
100 | - foreach ( $arrFoldersName as $index => $folderName ) |
|
100 | + foreach ($arrFoldersName as $index => $folderName) |
|
101 | 101 | { |
102 | - $arrFoldersName[ $index ] = $this->getConfig () |
|
103 | - ->replaceReservedWord ( $folderName ); |
|
102 | + $arrFoldersName[$index] = $this->getConfig() |
|
103 | + ->replaceReservedWord($folderName); |
|
104 | 104 | } |
105 | 105 | |
106 | - return implode ( DIRECTORY_SEPARATOR , array_filter ( $arrFoldersName ) ); |
|
106 | + return implode(DIRECTORY_SEPARATOR, array_filter($arrFoldersName)); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
110 | 110 | * Analisa os caminhos das pastas base |
111 | 111 | */ |
112 | - public function parseLocation ( $basePath ) |
|
112 | + public function parseLocation($basePath) |
|
113 | 113 | { |
114 | 114 | |
115 | - $arrBase = array ( |
|
116 | - $basePath , |
|
115 | + $arrBase = array( |
|
116 | + $basePath, |
|
117 | 117 | $this->config->path |
118 | 118 | ); |
119 | 119 | |
120 | - $this->baseLocation = $this->filterLocation ( $arrBase ); |
|
120 | + $this->baseLocation = $this->filterLocation($arrBase); |
|
121 | 121 | |
122 | 122 | # pasta com nome do driver do banco |
123 | 123 | $driverBase = ''; |
124 | - if ( (bool) @$this->config->{"folder-database"} ) |
|
124 | + if ((bool) @$this->config->{"folder-database"} ) |
|
125 | 125 | { |
126 | - $classDriver = explode ( '\\' , get_class ( $this->driver ) ); |
|
127 | - $driverBase = end ( $classDriver ); |
|
126 | + $classDriver = explode('\\', get_class($this->driver)); |
|
127 | + $driverBase = end($classDriver); |
|
128 | 128 | } |
129 | 129 | $folderName = ''; |
130 | - if ( (bool) @$this->config->{"folder-name"} ) |
|
130 | + if ((bool) @$this->config->{"folder-name"} ) |
|
131 | 131 | { |
132 | - $folderName = $this->getClassName ( trim ( $this->config->{"folder-name"} ) ); |
|
132 | + $folderName = $this->getClassName(trim($this->config->{"folder-name"} )); |
|
133 | 133 | } |
134 | 134 | |
135 | - if ( $this->config->hasSchemas () ) |
|
135 | + if ($this->config->hasSchemas()) |
|
136 | 136 | { |
137 | 137 | |
138 | - $schemas = $this->config->getSchemas (); |
|
139 | - foreach ( $schemas as $schema ) |
|
138 | + $schemas = $this->config->getSchemas(); |
|
139 | + foreach ($schemas as $schema) |
|
140 | 140 | { |
141 | - $arrUrl = array ( |
|
142 | - $this->baseLocation , |
|
143 | - $driverBase , |
|
144 | - $folderName , |
|
145 | - $this->getClassName ( $schema ) |
|
141 | + $arrUrl = array( |
|
142 | + $this->baseLocation, |
|
143 | + $driverBase, |
|
144 | + $folderName, |
|
145 | + $this->getClassName($schema) |
|
146 | 146 | ); |
147 | 147 | |
148 | - $this->location[ $schema ] = $this->filterLocation ( $arrUrl ); |
|
149 | - unset( $arrUrl ); |
|
148 | + $this->location[$schema] = $this->filterLocation($arrUrl); |
|
149 | + unset($arrUrl); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | } else |
153 | 153 | { |
154 | - $url = array ( |
|
155 | - $this->baseLocation , |
|
156 | - $driverBase , |
|
157 | - $folderName , |
|
158 | - $this->getClassName ( |
|
159 | - $this->getConfig () |
|
160 | - ->getDatabase () |
|
154 | + $url = array( |
|
155 | + $this->baseLocation, |
|
156 | + $driverBase, |
|
157 | + $folderName, |
|
158 | + $this->getClassName( |
|
159 | + $this->getConfig() |
|
160 | + ->getDatabase() |
|
161 | 161 | ) |
162 | 162 | ); |
163 | - $this->location = array ( $this->filterLocation ( $url ) ); |
|
164 | - unset( $url ); |
|
163 | + $this->location = array($this->filterLocation($url)); |
|
164 | + unset($url); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
169 | 169 | * @return AdapterConfig\AbstractAdapter |
170 | 170 | */ |
171 | - public function getConfig () |
|
171 | + public function getConfig() |
|
172 | 172 | { |
173 | 173 | return $this->config; |
174 | 174 | } |
175 | 175 | |
176 | 176 | /* Get current time */ |
177 | - public function startTime () |
|
177 | + public function startTime() |
|
178 | 178 | { |
179 | 179 | echo "\033[1;32mStarting..\033[0m\n"; |
180 | - $this->startTime = microtime ( true ); |
|
180 | + $this->startTime = microtime(true); |
|
181 | 181 | } |
182 | 182 | |
183 | - private function getRunTime () |
|
183 | + private function getRunTime() |
|
184 | 184 | { |
185 | - return round ( ( microtime ( true ) - $this->startTime ) , 3 ); |
|
185 | + return round((microtime(true) - $this->startTime), 3); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
189 | 189 | * @param $objMakeFile |
190 | 190 | */ |
191 | - private function generateFilesFixed ( FilesFixeds $objFilesFixeds ) |
|
191 | + private function generateFilesFixed(FilesFixeds $objFilesFixeds) |
|
192 | 192 | { |
193 | - if ( $objFilesFixeds->hasData () ) |
|
193 | + if ($objFilesFixeds->hasData()) |
|
194 | 194 | { |
195 | 195 | $file = $this->baseLocation |
196 | 196 | . DIRECTORY_SEPARATOR |
197 | - . $objFilesFixeds->getFileName () |
|
197 | + . $objFilesFixeds->getFileName() |
|
198 | 198 | . '.php'; |
199 | 199 | |
200 | - $tpl = $this->getParsedTplContents ( $objFilesFixeds->getTpl () ); |
|
201 | - self::makeSourcer ( $file , $tpl , true ); |
|
200 | + $tpl = $this->getParsedTplContents($objFilesFixeds->getTpl()); |
|
201 | + self::makeSourcer($file, $tpl, true); |
|
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
206 | 206 | * Executa o Make, criando arquivos e Diretorios |
207 | 207 | */ |
208 | - public function run () |
|
208 | + public function run() |
|
209 | 209 | { |
210 | 210 | $cur = 0; |
211 | 211 | $numFilesCreated = 0; |
212 | 212 | $numFilesIgnored = 0; |
213 | 213 | |
214 | - $this->startTime (); |
|
215 | - $this->waitOfDatabase ( $cur ); |
|
214 | + $this->startTime(); |
|
215 | + $this->waitOfDatabase($cur); |
|
216 | 216 | |
217 | - $this->max = $this->driver->getTotalTables () * $this->countDiretory (); |
|
218 | - $progressBar = ProgressBar::getInstance ()->setMaxByte ( $this->max ); |
|
217 | + $this->max = $this->driver->getTotalTables() * $this->countDiretory(); |
|
218 | + $progressBar = ProgressBar::getInstance()->setMaxByte($this->max); |
|
219 | 219 | |
220 | - foreach ( $this->location as $schema => $location ) |
|
220 | + foreach ($this->location as $schema => $location) |
|
221 | 221 | { |
222 | - foreach ( $this->factoryMakerFile () as $objMakeFile ) |
|
222 | + foreach ($this->factoryMakerFile() as $objMakeFile) |
|
223 | 223 | { |
224 | - $path = $location . DIRECTORY_SEPARATOR . $objMakeFile->getPastName (); |
|
225 | - if ( $this->config->isCleanTrash () ) |
|
224 | + $path = $location . DIRECTORY_SEPARATOR . $objMakeFile->getPastName(); |
|
225 | + if ($this->config->isCleanTrash()) |
|
226 | 226 | { |
227 | - CleanTrash::getInstance ()->run ( $path , $this->driver , $schema ); |
|
227 | + CleanTrash::getInstance()->run($path, $this->driver, $schema); |
|
228 | 228 | } |
229 | - self::makeDir ( $path ); |
|
229 | + self::makeDir($path); |
|
230 | 230 | |
231 | 231 | #Cria as Classes de Exceção e Abstratas |
232 | - foreach ( $objMakeFile->getListFilesFixed () as $nameObject ) |
|
232 | + foreach ($objMakeFile->getListFilesFixed() as $nameObject) |
|
233 | 233 | { |
234 | - $this->generateFilesFixed ( $objMakeFile->getFilesFixeds ( $nameObject ) ); |
|
234 | + $this->generateFilesFixed($objMakeFile->getFilesFixeds($nameObject)); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | #Cria as Classes do Banco |
238 | - foreach ( $this->driver->getTables ( $schema ) as $key => $objTables ) |
|
238 | + foreach ($this->driver->getTables($schema) as $key => $objTables) |
|
239 | 239 | { |
240 | 240 | $file = $path . DIRECTORY_SEPARATOR |
241 | - . self::getClassName ( $objTables->getName () ) . '.php'; |
|
241 | + . self::getClassName($objTables->getName()) . '.php'; |
|
242 | 242 | |
243 | - $tpl = $this->getParsedTplContents ( |
|
244 | - $objMakeFile->getFileTpl () , |
|
245 | - $objMakeFile->parseRelation ( $this , $objTables ) , |
|
246 | - $objTables , |
|
243 | + $tpl = $this->getParsedTplContents( |
|
244 | + $objMakeFile->getFileTpl(), |
|
245 | + $objMakeFile->parseRelation($this, $objTables), |
|
246 | + $objTables, |
|
247 | 247 | $objMakeFile |
248 | 248 | |
249 | 249 | ); |
250 | - if ( self::makeSourcer ( $file , $tpl , $objMakeFile->isOverwrite () ) ) |
|
250 | + if (self::makeSourcer($file, $tpl, $objMakeFile->isOverwrite())) |
|
251 | 251 | { |
252 | - ++ $numFilesCreated; |
|
252 | + ++$numFilesCreated; |
|
253 | 253 | } else |
254 | 254 | { |
255 | - ++ $numFilesIgnored; |
|
255 | + ++$numFilesIgnored; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | ++$cur; |
259 | - $progressBar->setProgress ( $cur )->render(); |
|
259 | + $progressBar->setProgress($cur)->render(); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | } |
263 | 263 | |
264 | - $this->reportProcess ( $numFilesCreated , $numFilesIgnored ); |
|
264 | + $this->reportProcess($numFilesCreated, $numFilesIgnored); |
|
265 | 265 | $progressBar->finish(); |
266 | 266 | } |
267 | 267 | |
268 | - private function waitOfDatabase ( &$cur ) |
|
268 | + private function waitOfDatabase(&$cur) |
|
269 | 269 | { |
270 | - printf ( "\033[1;33mWait, the database is being analyzed..\033[0m\n" ); |
|
271 | - $this->driver->runDatabase (); |
|
270 | + printf("\033[1;33mWait, the database is being analyzed..\033[0m\n"); |
|
271 | + $this->driver->runDatabase(); |
|
272 | 272 | } |
273 | 273 | |
274 | - private function reportProcess ( $numFilesCreated = 0 , $numFilesIgnored = 0 ) |
|
274 | + private function reportProcess($numFilesCreated = 0, $numFilesIgnored = 0) |
|
275 | 275 | { |
276 | - if ( $this->config->isStatusEnabled () ) |
|
276 | + if ($this->config->isStatusEnabled()) |
|
277 | 277 | { |
278 | - $databases = count ( $this->location ); |
|
279 | - $countDir = $this->countDiretory (); |
|
280 | - $totalTable = $this->driver->getTotalTables (); |
|
278 | + $databases = count($this->location); |
|
279 | + $countDir = $this->countDiretory(); |
|
280 | + $totalTable = $this->driver->getTotalTables(); |
|
281 | 281 | $totalFiles = $numFilesIgnored + $numFilesCreated; |
282 | - $totalFilesDeleted = CleanTrash::getInstance ()->getNumFilesDeleted (); |
|
282 | + $totalFilesDeleted = CleanTrash::getInstance()->getNumFilesDeleted(); |
|
283 | 283 | echo "\n------"; |
284 | - printf ( "\n\r-Files generated/updated: \033[1;33m%s\033[0m" , $numFilesCreated ); |
|
285 | - printf ( "\n\r-Files not upgradeable: \033[1;33m%s\033[0m" , $numFilesIgnored ); |
|
286 | - printf ( "\n\r-Files deleted: \033[1;33m%s\033[0m" , $totalFilesDeleted ); |
|
287 | - printf ( "\n\r-Total files analyzed: \033[1;33m%s of %s\033[0m" , $totalFiles , $this->max ); |
|
288 | - printf ( "\n\r-Diretories: \033[1;33m%s\033[0m" , $databases * $countDir ); |
|
289 | - printf ( "\n\r-Scanned tables: \033[1;33m%s\033[0m" , $totalTable ); |
|
290 | - printf ( "\n\r-Execution time: \033[1;33m%ssec\033[0m" , $this->getRunTime () ); |
|
284 | + printf("\n\r-Files generated/updated: \033[1;33m%s\033[0m", $numFilesCreated); |
|
285 | + printf("\n\r-Files not upgradeable: \033[1;33m%s\033[0m", $numFilesIgnored); |
|
286 | + printf("\n\r-Files deleted: \033[1;33m%s\033[0m", $totalFilesDeleted); |
|
287 | + printf("\n\r-Total files analyzed: \033[1;33m%s of %s\033[0m", $totalFiles, $this->max); |
|
288 | + printf("\n\r-Diretories: \033[1;33m%s\033[0m", $databases * $countDir); |
|
289 | + printf("\n\r-Scanned tables: \033[1;33m%s\033[0m", $totalTable); |
|
290 | + printf("\n\r-Execution time: \033[1;33m%ssec\033[0m", $this->getRunTime()); |
|
291 | 291 | echo "\n------"; |
292 | 292 | } |
293 | 293 | } |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | * |
298 | 298 | * @return AbstractAdapter[] |
299 | 299 | */ |
300 | - public function factoryMakerFile () |
|
300 | + public function factoryMakerFile() |
|
301 | 301 | { |
302 | - return $this->config->getMakeFileInstances (); |
|
302 | + return $this->config->getMakeFileInstances(); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -307,16 +307,16 @@ discard block |
||
307 | 307 | * |
308 | 308 | * @return int |
309 | 309 | */ |
310 | - public function countDiretory () |
|
310 | + public function countDiretory() |
|
311 | 311 | { |
312 | - if ( null === $this->countDir ) |
|
312 | + if (null === $this->countDir) |
|
313 | 313 | { |
314 | 314 | $this->countDir = 1; |
315 | - foreach ( $this->factoryMakerFile () as $abstractAdapter ) |
|
315 | + foreach ($this->factoryMakerFile() as $abstractAdapter) |
|
316 | 316 | { |
317 | - if ( $abstractAdapter->hasDiretory () ) |
|
317 | + if ($abstractAdapter->hasDiretory()) |
|
318 | 318 | { |
319 | - ++ $this->countDir; |
|
319 | + ++$this->countDir; |
|
320 | 320 | } |
321 | 321 | } |
322 | 322 | } |
@@ -332,25 +332,25 @@ discard block |
||
332 | 332 | * |
333 | 333 | * @return String |
334 | 334 | */ |
335 | - protected function getParsedTplContents ( |
|
336 | - $tplFile , $vars = array () , \Classes\Db\DbTable $objTables = null , |
|
335 | + protected function getParsedTplContents( |
|
336 | + $tplFile, $vars = array(), \Classes\Db\DbTable $objTables = null, |
|
337 | 337 | $objMakeFile = null |
338 | - ){ |
|
338 | + ) { |
|
339 | 339 | |
340 | - $arrUrl = array ( |
|
341 | - __DIR__ , |
|
342 | - 'templates' , |
|
343 | - $this->config->framework , |
|
340 | + $arrUrl = array( |
|
341 | + __DIR__, |
|
342 | + 'templates', |
|
343 | + $this->config->framework, |
|
344 | 344 | $tplFile |
345 | 345 | ); |
346 | 346 | |
347 | - $filePath = implode ( DIRECTORY_SEPARATOR , filter_var_array ( $arrUrl ) ); |
|
347 | + $filePath = implode(DIRECTORY_SEPARATOR, filter_var_array($arrUrl)); |
|
348 | 348 | |
349 | - extract ( $vars ); |
|
350 | - ob_start (); |
|
349 | + extract($vars); |
|
350 | + ob_start(); |
|
351 | 351 | require $filePath; |
352 | - $data = ob_get_contents (); |
|
353 | - ob_end_clean (); |
|
352 | + $data = ob_get_contents(); |
|
353 | + ob_end_clean(); |
|
354 | 354 | |
355 | 355 | return $data; |
356 | 356 | } |
@@ -108,6 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | /** |
110 | 110 | * Analisa os caminhos das pastas base |
111 | + * @param string $basePath |
|
111 | 112 | */ |
112 | 113 | public function parseLocation ( $basePath ) |
113 | 114 | { |
@@ -265,6 +266,9 @@ discard block |
||
265 | 266 | $progressBar->finish(); |
266 | 267 | } |
267 | 268 | |
269 | + /** |
|
270 | + * @param integer $cur |
|
271 | + */ |
|
268 | 272 | private function waitOfDatabase ( &$cur ) |
269 | 273 | { |
270 | 274 | printf ( "\033[1;33mWait, the database is being analyzed..\033[0m\n" ); |
@@ -329,6 +333,7 @@ discard block |
||
329 | 333 | * parse a tpl file and return the result |
330 | 334 | * |
331 | 335 | * @param String $tplFile |
336 | + * @param AbstractAdapter $objMakeFile |
|
332 | 337 | * |
333 | 338 | * @return String |
334 | 339 | */ |
@@ -160,14 +160,14 @@ discard block |
||
160 | 160 | { |
161 | 161 | $update = new Update(); |
162 | 162 | $update->update () |
163 | - ->modifyTempName (); |
|
163 | + ->modifyTempName (); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | public function download ( $version ) |
167 | 167 | { |
168 | 168 | $update = new Update(); |
169 | 169 | $update->downloadVersion ( $version ) |
170 | - ->modifyTempName (); |
|
170 | + ->modifyTempName (); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | public function getVersion () |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $configIni = isset( $argv[ 'name-ini' ] ) |
194 | 194 | ? $argv[ 'name-ini' ] |
195 | 195 | : $this->_basePath |
196 | - . $this->configIniDefault; |
|
196 | + . $this->configIniDefault; |
|
197 | 197 | |
198 | 198 | $configTemp = $this->loadIniFile ( realpath ( $configIni ) ); |
199 | 199 | $configCurrent = self::parseConfigEnv ( $configTemp , $argv ); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | { |
208 | 208 | $frameworks = implode ( "\n\t" , $this->frameworkList ); |
209 | 209 | throw new \Exception( "list of frameworks: \n\t\033[1;33m" . $frameworks |
210 | - . "\n\033[0m" ); |
|
210 | + . "\n\033[0m" ); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | return $argv + array_filter ( $configCurrent ); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * @var array |
57 | 57 | */ |
58 | - private $argv = array (); |
|
58 | + private $argv = array(); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * @var \Classes\AdapterConfig\AbstractAdapter |
@@ -67,58 +67,58 @@ discard block |
||
67 | 67 | */ |
68 | 68 | private $adapterDriver; |
69 | 69 | |
70 | - private $frameworkList = array ( |
|
71 | - 'none' , |
|
72 | - 'zf1' , |
|
70 | + private $frameworkList = array( |
|
71 | + 'none', |
|
72 | + 'zf1', |
|
73 | 73 | 'phalcon' |
74 | 74 | ); |
75 | 75 | |
76 | - private $parameterList = array ( |
|
77 | - 'init' => 'Creates the necessary configuration file to start using the orm-generator.' , |
|
78 | - 'name-ini' => 'reference to another .ini file configuration (relative path).' , |
|
79 | - 'config-env' => 'orm-generator configuration environment.' , |
|
80 | - 'framework' => 'name framework used, which has the contents of the database configurations and framework template.' , |
|
81 | - 'driver' => 'database driver name (Ex.: pgsql).' , |
|
82 | - 'database' => 'database name.' , |
|
83 | - 'schema' => 'database schema name (one or more than one).' , |
|
84 | - 'tables' => 'table name (parameter can be used more then once).' , |
|
85 | - 'optional-classes' => 'List of optional Predefined classes to be created (Consult in github the list of each framework).' , |
|
86 | - 'clean-trash' => 'delete all files that do not belong to your Database due' , |
|
87 | - 'status' => 'show status of implementation carried out after completing the process.' , |
|
88 | - 'version' => 'shows the version of orm-generator.' , |
|
89 | - 'help' => "help command explaining all the options and manner of use." , |
|
90 | - 'path' => "specify where to create the files (default is current directory)." , |
|
91 | - 'update' => "Upgrade to latest version." , |
|
76 | + private $parameterList = array( |
|
77 | + 'init' => 'Creates the necessary configuration file to start using the orm-generator.', |
|
78 | + 'name-ini' => 'reference to another .ini file configuration (relative path).', |
|
79 | + 'config-env' => 'orm-generator configuration environment.', |
|
80 | + 'framework' => 'name framework used, which has the contents of the database configurations and framework template.', |
|
81 | + 'driver' => 'database driver name (Ex.: pgsql).', |
|
82 | + 'database' => 'database name.', |
|
83 | + 'schema' => 'database schema name (one or more than one).', |
|
84 | + 'tables' => 'table name (parameter can be used more then once).', |
|
85 | + 'optional-classes' => 'List of optional Predefined classes to be created (Consult in github the list of each framework).', |
|
86 | + 'clean-trash' => 'delete all files that do not belong to your Database due', |
|
87 | + 'status' => 'show status of implementation carried out after completing the process.', |
|
88 | + 'version' => 'shows the version of orm-generator.', |
|
89 | + 'help' => "help command explaining all the options and manner of use.", |
|
90 | + 'path' => "specify where to create the files (default is current directory).", |
|
91 | + 'update' => "Upgrade to latest version.", |
|
92 | 92 | 'download' => "download the reported version (ex. --download=1.5.0). " |
93 | 93 | ); |
94 | 94 | |
95 | - public function __construct ( $argv , $basePath , $numArgs ) |
|
95 | + public function __construct($argv, $basePath, $numArgs) |
|
96 | 96 | { |
97 | - if ( array_key_exists ( 'help' , $argv ) or ( $numArgs > 1 |
|
98 | - && count ( $argv ) < 1 ) |
|
97 | + if (array_key_exists('help', $argv) or ($numArgs > 1 |
|
98 | + && count($argv) < 1) |
|
99 | 99 | ) |
100 | 100 | { |
101 | - die ( $this->getUsage () ); |
|
101 | + die ($this->getUsage()); |
|
102 | 102 | } |
103 | - if ( array_key_exists ( 'version' , $argv ) ) |
|
103 | + if (array_key_exists('version', $argv)) |
|
104 | 104 | { |
105 | - die ( $this->getVersion () ); |
|
105 | + die ($this->getVersion()); |
|
106 | 106 | } |
107 | - if ( array_key_exists ( 'status' , $argv ) ) |
|
107 | + if (array_key_exists('status', $argv)) |
|
108 | 108 | { |
109 | - $argv[ 'status' ] = true; |
|
109 | + $argv['status'] = true; |
|
110 | 110 | } |
111 | - if ( array_key_exists ( 'update' , $argv ) ) |
|
111 | + if (array_key_exists('update', $argv)) |
|
112 | 112 | { |
113 | - die ( $this->update () ); |
|
113 | + die ($this->update()); |
|
114 | 114 | } |
115 | - if ( array_key_exists ( 'download' , $argv ) ) |
|
115 | + if (array_key_exists('download', $argv)) |
|
116 | 116 | { |
117 | - die ( $this->download ( $argv[ 'download' ] ) ); |
|
117 | + die ($this->download($argv['download'])); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | self::$version = Version::getVersion(); |
121 | - $this->argv = $this->parseConfig ( $basePath , $argv ); |
|
121 | + $this->argv = $this->parseConfig($basePath, $argv); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - public function getUsage () |
|
129 | + public function getUsage() |
|
130 | 130 | { |
131 | 131 | $version = self::$version; |
132 | - $list = $this->renderParam (); |
|
132 | + $list = $this->renderParam(); |
|
133 | 133 | |
134 | 134 | return <<<EOF |
135 | 135 | parameters: |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | EOF; |
141 | 141 | } |
142 | 142 | |
143 | - public function renderParam () |
|
143 | + public function renderParam() |
|
144 | 144 | { |
145 | 145 | $return = ""; |
146 | - foreach ( $this->parameterList as $param => $desc ) |
|
146 | + foreach ($this->parameterList as $param => $desc) |
|
147 | 147 | { |
148 | - if ( strlen ( $param ) < 5 ) |
|
148 | + if (strlen($param) < 5) |
|
149 | 149 | { |
150 | 150 | $return .= "\t--" . $param . "\t\t: " . $desc . "\n"; |
151 | 151 | } else |
@@ -158,21 +158,21 @@ discard block |
||
158 | 158 | return $return; |
159 | 159 | } |
160 | 160 | |
161 | - public function update () |
|
161 | + public function update() |
|
162 | 162 | { |
163 | 163 | $update = new Update(); |
164 | - $update->update () |
|
165 | - ->modifyTempName (); |
|
164 | + $update->update() |
|
165 | + ->modifyTempName(); |
|
166 | 166 | } |
167 | 167 | |
168 | - public function download ( $version ) |
|
168 | + public function download($version) |
|
169 | 169 | { |
170 | 170 | $update = new Update(); |
171 | - $update->downloadVersion ( $version ) |
|
172 | - ->modifyTempName (); |
|
171 | + $update->downloadVersion($version) |
|
172 | + ->modifyTempName(); |
|
173 | 173 | } |
174 | 174 | |
175 | - public function getVersion () |
|
175 | + public function getVersion() |
|
176 | 176 | { |
177 | 177 | $version = self::$version; |
178 | 178 | return "ORM Generator \nVersion: {$version}\ncreated by: Pedro Alarcao <https://github.com/pedro151/orm-generator>\n{$version->messageHasNewVersion()}"; |
@@ -187,31 +187,31 @@ discard block |
||
187 | 187 | * @return array |
188 | 188 | * @throws \Exception |
189 | 189 | */ |
190 | - private function parseConfig ( $basePath , $argv ) |
|
190 | + private function parseConfig($basePath, $argv) |
|
191 | 191 | { |
192 | 192 | $this->_basePath = $basePath; |
193 | 193 | |
194 | - $configIni = isset( $argv[ 'name-ini' ] ) |
|
195 | - ? $argv[ 'name-ini' ] |
|
194 | + $configIni = isset($argv['name-ini']) |
|
195 | + ? $argv['name-ini'] |
|
196 | 196 | : $this->_basePath |
197 | 197 | . $this->configIniDefault; |
198 | 198 | |
199 | - $configTemp = $this->loadIniFile ( realpath ( $configIni ) ); |
|
200 | - $configCurrent = self::parseConfigEnv ( $configTemp , $argv ); |
|
199 | + $configTemp = $this->loadIniFile(realpath($configIni)); |
|
200 | + $configCurrent = self::parseConfigEnv($configTemp, $argv); |
|
201 | 201 | |
202 | - if ( ! isset( $configCurrent[ 'framework' ] ) ) |
|
202 | + if ( ! isset($configCurrent['framework'])) |
|
203 | 203 | { |
204 | - throw new \Exception( "configure which framework you want to use! \n" ); |
|
204 | + throw new \Exception("configure which framework you want to use! \n"); |
|
205 | 205 | } |
206 | 206 | |
207 | - if ( ! in_array ( $configCurrent[ 'framework' ] , $this->frameworkList ) ) |
|
207 | + if ( ! in_array($configCurrent['framework'], $this->frameworkList)) |
|
208 | 208 | { |
209 | - $frameworks = implode ( "\n\t" , $this->frameworkList ); |
|
210 | - throw new \Exception( "list of frameworks: \n\t\033[1;33m" . $frameworks |
|
211 | - . "\n\033[0m" ); |
|
209 | + $frameworks = implode("\n\t", $this->frameworkList); |
|
210 | + throw new \Exception("list of frameworks: \n\t\033[1;33m" . $frameworks |
|
211 | + . "\n\033[0m"); |
|
212 | 212 | } |
213 | 213 | |
214 | - return $argv + array_filter ( $configCurrent ); |
|
214 | + return $argv + array_filter($configCurrent); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -221,24 +221,24 @@ discard block |
||
221 | 221 | * |
222 | 222 | * @return string |
223 | 223 | */ |
224 | - private static function parseConfigEnv ( $configTemp , $argv ) |
|
224 | + private static function parseConfigEnv($configTemp, $argv) |
|
225 | 225 | { |
226 | - $thisSection = isset( $configTemp[ key ( $configTemp ) ][ 'config-env' ] ) |
|
227 | - ? $configTemp[ key ( |
|
226 | + $thisSection = isset($configTemp[key($configTemp)]['config-env']) |
|
227 | + ? $configTemp[key( |
|
228 | 228 | $configTemp |
229 | - ) ][ 'config-env' ] : null; |
|
229 | + )]['config-env'] : null; |
|
230 | 230 | |
231 | - $thisSection = isset( $argv[ 'config-env' ] ) ? $argv[ 'config-env' ] |
|
231 | + $thisSection = isset($argv['config-env']) ? $argv['config-env'] |
|
232 | 232 | : $thisSection; |
233 | 233 | |
234 | - if ( isset( $configTemp[ $thisSection ][ 'extends' ] ) ) |
|
234 | + if (isset($configTemp[$thisSection]['extends'])) |
|
235 | 235 | { |
236 | 236 | #faz marge da config principal com a config extendida |
237 | - return $configTemp[ $thisSection ] |
|
238 | - + $configTemp[ $configTemp[ $thisSection ][ 'extends' ] ]; |
|
237 | + return $configTemp[$thisSection] |
|
238 | + + $configTemp[$configTemp[$thisSection]['extends']]; |
|
239 | 239 | } |
240 | 240 | |
241 | - return $configTemp[ key ( $configTemp ) ]; |
|
241 | + return $configTemp[key($configTemp)]; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -252,32 +252,32 @@ discard block |
||
252 | 252 | * @throws \Exception |
253 | 253 | * @return array |
254 | 254 | */ |
255 | - protected function loadIniFile ( $filename ) |
|
255 | + protected function loadIniFile($filename) |
|
256 | 256 | { |
257 | - if ( ! is_file ( $filename ) ) |
|
257 | + if ( ! is_file($filename)) |
|
258 | 258 | { |
259 | - throw new \Exception( "\033[0;31mError: configuration file does not exist! \033[0m\n" ); |
|
259 | + throw new \Exception("\033[0;31mError: configuration file does not exist! \033[0m\n"); |
|
260 | 260 | } |
261 | 261 | |
262 | - $loaded = parse_ini_file ( $filename , true ); |
|
263 | - $iniArray = array (); |
|
264 | - foreach ( $loaded as $key => $data ) |
|
262 | + $loaded = parse_ini_file($filename, true); |
|
263 | + $iniArray = array(); |
|
264 | + foreach ($loaded as $key => $data) |
|
265 | 265 | { |
266 | - $pieces = explode ( $this->sectionSeparator , $key ); |
|
267 | - $thisSection = trim ( $pieces[ 0 ] ); |
|
268 | - switch ( count ( $pieces ) ) |
|
266 | + $pieces = explode($this->sectionSeparator, $key); |
|
267 | + $thisSection = trim($pieces[0]); |
|
268 | + switch (count($pieces)) |
|
269 | 269 | { |
270 | 270 | case 1: |
271 | - $iniArray[ $thisSection ] = $data; |
|
271 | + $iniArray[$thisSection] = $data; |
|
272 | 272 | break; |
273 | 273 | |
274 | 274 | case 2: |
275 | - $extendedSection = trim ( $pieces[ 1 ] ); |
|
276 | - $iniArray[ $thisSection ] = array_merge ( array ( 'extends' => $extendedSection ) , $data ); |
|
275 | + $extendedSection = trim($pieces[1]); |
|
276 | + $iniArray[$thisSection] = array_merge(array('extends' => $extendedSection), $data); |
|
277 | 277 | break; |
278 | 278 | |
279 | 279 | default: |
280 | - throw new \Exception( "Section '$thisSection' may not extend multiple sections in $filename" ); |
|
280 | + throw new \Exception("Section '$thisSection' may not extend multiple sections in $filename"); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
@@ -290,16 +290,16 @@ discard block |
||
290 | 290 | * @return \Classes\AdapterConfig\AbstractAdapter |
291 | 291 | * |
292 | 292 | */ |
293 | - private function factoryConfig () |
|
293 | + private function factoryConfig() |
|
294 | 294 | { |
295 | - switch ( strtolower ( $this->argv[ 'framework' ] ) ) |
|
295 | + switch (strtolower($this->argv['framework'])) |
|
296 | 296 | { |
297 | 297 | case 'zf1': |
298 | - return new ZendFrameworkOne( $this->argv ); |
|
298 | + return new ZendFrameworkOne($this->argv); |
|
299 | 299 | case 'phalcon': |
300 | - return new Phalcon( $this->argv ); |
|
300 | + return new Phalcon($this->argv); |
|
301 | 301 | default: |
302 | - return new None( $this->argv ); |
|
302 | + return new None($this->argv); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | } |
@@ -311,33 +311,33 @@ discard block |
||
311 | 311 | * |
312 | 312 | * @return AdaptersDriver\AbsractAdapter |
313 | 313 | */ |
314 | - private function factoryDriver ( AdapterConfig\AbstractAdapter $config ) |
|
314 | + private function factoryDriver(AdapterConfig\AbstractAdapter $config) |
|
315 | 315 | { |
316 | - switch ( $this->argv[ 'driver' ] ) |
|
316 | + switch ($this->argv['driver']) |
|
317 | 317 | { |
318 | 318 | case 'pgsql': |
319 | 319 | case 'pdo_pgsql': |
320 | - return new Pgsql( $config ); |
|
320 | + return new Pgsql($config); |
|
321 | 321 | case 'mysql': |
322 | 322 | case 'pdo_mysql': |
323 | - return new Mysql( $config ); |
|
323 | + return new Mysql($config); |
|
324 | 324 | case 'mssql': |
325 | - return new Mssql( $config ); |
|
325 | + return new Mssql($config); |
|
326 | 326 | case 'dblib': |
327 | - return new Dblib( $config ); |
|
327 | + return new Dblib($config); |
|
328 | 328 | case 'sqlsrv': |
329 | - return new Sqlsrv( $config ); |
|
329 | + return new Sqlsrv($config); |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
334 | 334 | * @return AdapterConfig\AbstractAdapter |
335 | 335 | */ |
336 | - public function getAdapterConfig () |
|
336 | + public function getAdapterConfig() |
|
337 | 337 | { |
338 | - if ( ! $this->adapterConfig instanceof AbstractAdapter ) |
|
338 | + if ( ! $this->adapterConfig instanceof AbstractAdapter) |
|
339 | 339 | { |
340 | - $this->adapterConfig = $this->factoryConfig (); |
|
340 | + $this->adapterConfig = $this->factoryConfig(); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | return $this->adapterConfig; |
@@ -346,11 +346,11 @@ discard block |
||
346 | 346 | /** |
347 | 347 | * @return AdaptersDriver\AbsractAdapter |
348 | 348 | */ |
349 | - public function getAdapterDriver ( AdapterConfig\AbstractAdapter $config ) |
|
349 | + public function getAdapterDriver(AdapterConfig\AbstractAdapter $config) |
|
350 | 350 | { |
351 | - if ( ! $this->adapterDriver ) |
|
351 | + if ( ! $this->adapterDriver) |
|
352 | 352 | { |
353 | - $this->adapterDriver = $this->factoryDriver ( $config ); |
|
353 | + $this->adapterDriver = $this->factoryDriver($config); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | return $this->adapterDriver; |
@@ -3,21 +3,21 @@ |
||
3 | 3 | /** |
4 | 4 | * Application Model Peer |
5 | 5 | * |
6 | - * <?=$this->config->last_modify."\n"?> |
|
6 | + * <?=$this->config->last_modify . "\n"?> |
|
7 | 7 | * |
8 | 8 | * Tabela definida por 'tablename' |
9 | 9 | * |
10 | 10 | * @package <?=$objTables->getNamespace()?><?="\n"?> |
11 | 11 | * @subpackage Peer |
12 | - * @author <?=$this->config->author."\n"?> |
|
12 | + * @author <?=$this->config->author . "\n"?> |
|
13 | 13 | * |
14 | - * @copyright <?=$this->config->copyright."\n"?> |
|
15 | - * @license <?=$this->config->license."\n"?> |
|
16 | - * @link <?=$this->config->link."\n"?> |
|
17 | - * @version <?=$this->config->version."\n"?> |
|
14 | + * @copyright <?=$this->config->copyright . "\n"?> |
|
15 | + * @license <?=$this->config->license . "\n"?> |
|
16 | + * @link <?=$this->config->link . "\n"?> |
|
17 | + * @version <?=$this->config->version . "\n"?> |
|
18 | 18 | */ |
19 | 19 | |
20 | -class <?=$objTables->getNamespace()?>_Peer_<?=\Classes\Maker\AbstractMaker::getClassName ( $objTables->getName () )?> extends <?=$objTables->getNamespace()?$objTables->getNamespace()."_":''?>DbTable_<?=\Classes\Maker\AbstractMaker::getClassName ( $objTables->getName () ) . "\n"?> |
|
20 | +class <?=$objTables->getNamespace()?>_Peer_<?=\Classes\Maker\AbstractMaker::getClassName($objTables->getName())?> extends <?=$objTables->getNamespace() ? $objTables->getNamespace() . "_" : ''?>DbTable_<?=\Classes\Maker\AbstractMaker::getClassName($objTables->getName()) . "\n"?> |
|
21 | 21 | { |
22 | 22 | /* @TODO Codifique aqui */ |
23 | 23 | } |
@@ -19,6 +19,6 @@ |
||
19 | 19 | |
20 | 20 | public function parseRelation ( \Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable ) |
21 | 21 | { |
22 | - return array(); |
|
22 | + return array(); |
|
23 | 23 | } |
24 | 24 | } |
@@ -14,14 +14,14 @@ |
||
14 | 14 | */ |
15 | 15 | public $pastName = 'Peer'; |
16 | 16 | protected $fileTpl = "peer.php"; |
17 | - protected $fileFixedData = array ( |
|
18 | - 'exception' => array ( |
|
19 | - 'tpl' => "model_exception.php" , |
|
17 | + protected $fileFixedData = array( |
|
18 | + 'exception' => array( |
|
19 | + 'tpl' => "model_exception.php", |
|
20 | 20 | 'name' => "Exception" |
21 | 21 | ) |
22 | 22 | ); |
23 | 23 | |
24 | - public function parseRelation ( \Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable ) |
|
24 | + public function parseRelation(\Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable) |
|
25 | 25 | { |
26 | 26 | return array(); |
27 | 27 | } |
@@ -81,7 +81,7 @@ |
||
81 | 81 | $class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) ); |
82 | 82 | |
83 | 83 | if(!in_array($class,$dependents)){ |
84 | - $dependents[] = $class; |
|
84 | + $dependents[] = $class; |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | } |
@@ -15,14 +15,14 @@ discard block |
||
15 | 15 | |
16 | 16 | public $pastName = 'DbTable'; |
17 | 17 | protected $fileTpl = "dbtable.php"; |
18 | - protected $fileFixedData = array ( |
|
19 | - 'parentclass' => array ( |
|
20 | - 'name' => "TableAbstract" , |
|
18 | + protected $fileFixedData = array( |
|
19 | + 'parentclass' => array( |
|
20 | + 'name' => "TableAbstract", |
|
21 | 21 | 'tpl' => "dbtable_abstract.php" |
22 | 22 | ) |
23 | 23 | ); |
24 | 24 | |
25 | - protected $overwrite = true; |
|
25 | + protected $overwrite = true; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @param \Classes\MakerFile $makerFile |
@@ -30,70 +30,70 @@ 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 | $referenceMap = ''; |
36 | - $references = array (); |
|
36 | + $references = array(); |
|
37 | 37 | $dependentTables = ''; |
38 | - $dependents = array (); |
|
39 | - foreach ( $dbTable->getForeingkeys () as $objColumn ) |
|
38 | + $dependents = array(); |
|
39 | + foreach ($dbTable->getForeingkeys() as $objColumn) |
|
40 | 40 | { |
41 | - $constrant = $objColumn->getFks (); |
|
42 | - $variable = $constrant->getNameConstrant () . ZendFrameworkOne::SEPARETOR . $objColumn->getName (); |
|
41 | + $constrant = $objColumn->getFks(); |
|
42 | + $variable = $constrant->getNameConstrant() . ZendFrameworkOne::SEPARETOR . $objColumn->getName(); |
|
43 | 43 | |
44 | - $arrClass = array ( |
|
45 | - $makerFile->getConfig ()->createClassNamespace ( $constrant ), |
|
44 | + $arrClass = array( |
|
45 | + $makerFile->getConfig()->createClassNamespace($constrant), |
|
46 | 46 | 'DbTable', |
47 | - AbstractMaker::getClassName ( $constrant->getTable () ) |
|
47 | + AbstractMaker::getClassName($constrant->getTable()) |
|
48 | 48 | ); |
49 | - $class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) ); |
|
49 | + $class = implode(ZendFrameworkOne::SEPARETOR, array_filter($arrClass)); |
|
50 | 50 | |
51 | - $references[] = sprintf ( |
|
51 | + $references[] = sprintf( |
|
52 | 52 | " |
53 | 53 | '%s' => array ( |
54 | 54 | 'columns' => '%s' , |
55 | 55 | 'refTableClass' => '%s', |
56 | 56 | 'refColumns' =>'%s' |
57 | 57 | )", |
58 | - AbstractMaker::getClassName ( $variable ), |
|
59 | - $objColumn->getName (), |
|
58 | + AbstractMaker::getClassName($variable), |
|
59 | + $objColumn->getName(), |
|
60 | 60 | $class, |
61 | - $constrant->getColumn () |
|
61 | + $constrant->getColumn() |
|
62 | 62 | |
63 | 63 | ); |
64 | 64 | } |
65 | 65 | |
66 | - if ( sizeof ( $references ) > 0 ) |
|
66 | + if (sizeof($references) > 0) |
|
67 | 67 | { |
68 | 68 | $referenceMap = "protected \$_referenceMap = array(" . |
69 | - join ( ',', $references ) . "\n );"; |
|
69 | + join(',', $references) . "\n );"; |
|
70 | 70 | } |
71 | 71 | |
72 | - foreach ( $dbTable->getDependences () as $objColumn ) |
|
72 | + foreach ($dbTable->getDependences() as $objColumn) |
|
73 | 73 | { |
74 | - foreach ( $objColumn->getDependences () as $dependence ) |
|
74 | + foreach ($objColumn->getDependences() as $dependence) |
|
75 | 75 | { |
76 | - $arrClass = array ( |
|
77 | - $makerFile->getConfig ()->createClassNamespace ( $dependence ), |
|
76 | + $arrClass = array( |
|
77 | + $makerFile->getConfig()->createClassNamespace($dependence), |
|
78 | 78 | 'DbTable', |
79 | - AbstractMaker::getClassName ( $dependence->getTable () ) |
|
79 | + AbstractMaker::getClassName($dependence->getTable()) |
|
80 | 80 | ); |
81 | - $class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) ); |
|
81 | + $class = implode(ZendFrameworkOne::SEPARETOR, array_filter($arrClass)); |
|
82 | 82 | |
83 | - if(!in_array($class,$dependents)){ |
|
83 | + if ( ! in_array($class, $dependents)) { |
|
84 | 84 | $dependents[] = $class; |
85 | 85 | } |
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | - if ( sizeof ( $dependents ) > 0 ) |
|
89 | + if (sizeof($dependents) > 0) |
|
90 | 90 | { |
91 | 91 | $dependentTables = "protected \$_dependentTables = array(\n '" . |
92 | - join ( "',\n '", $dependents ) . "'\n );"; |
|
92 | + join("',\n '", $dependents) . "'\n );"; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
96 | - return array ( |
|
96 | + return array( |
|
97 | 97 | 'referenceMap' => $referenceMap, |
98 | 98 | 'dependentTables' => $dependentTables |
99 | 99 | ); |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | const SEPARETOR = "_"; |
26 | 26 | |
27 | - protected function init () |
|
27 | + protected function init() |
|
28 | 28 | { |
29 | 29 | } |
30 | 30 | |
@@ -33,50 +33,50 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return array |
35 | 35 | */ |
36 | - protected function getParams () |
|
36 | + protected function getParams() |
|
37 | 37 | { |
38 | - if ( ! $this->config or ! $this->isValidFrameworkFiles () ) |
|
38 | + if ( ! $this->config or ! $this->isValidFrameworkFiles()) |
|
39 | 39 | { |
40 | - return array (); |
|
40 | + return array(); |
|
41 | 41 | } |
42 | 42 | |
43 | - return array ( |
|
43 | + return array( |
|
44 | 44 | //Driver do banco de dados |
45 | - 'driver' => $this->config[ 'adapter' ] , |
|
45 | + 'driver' => $this->config['adapter'], |
|
46 | 46 | //Nome do banco de dados |
47 | - 'database' => $this->config[ 'params' ][ 'dbname' ] , |
|
47 | + 'database' => $this->config['params']['dbname'], |
|
48 | 48 | //Host do banco |
49 | - 'host' => $this->config[ 'params' ][ 'host' ] , |
|
49 | + 'host' => $this->config['params']['host'], |
|
50 | 50 | //Port do banco |
51 | - 'port' => isset( $this->config[ 'params' ][ 'port' ] ) |
|
52 | - ? $this->config[ 'params' ][ 'port' ] : '' , |
|
51 | + 'port' => isset($this->config['params']['port']) |
|
52 | + ? $this->config['params']['port'] : '', |
|
53 | 53 | //usuario do banco |
54 | - 'username' => $this->config[ 'params' ][ 'username' ] , |
|
54 | + 'username' => $this->config['params']['username'], |
|
55 | 55 | //senha do banco |
56 | - 'password' => $this->config[ 'params' ][ 'password' ] , |
|
56 | + 'password' => $this->config['params']['password'], |
|
57 | 57 | ); |
58 | 58 | } |
59 | 59 | |
60 | - protected function parseFrameworkConfig () |
|
60 | + protected function parseFrameworkConfig() |
|
61 | 61 | { |
62 | - if ( ! $this->isValidFrameworkFiles () ) |
|
62 | + if ( ! $this->isValidFrameworkFiles()) |
|
63 | 63 | { |
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | - $frameworkIni = $this->getFrameworkIni (); |
|
67 | + $frameworkIni = $this->getFrameworkIni(); |
|
68 | 68 | |
69 | 69 | require_once 'Zend/Config/Ini.php'; |
70 | 70 | |
71 | 71 | $objConfig = new \Zend_Config_Ini( |
72 | - realpath ( $frameworkIni ) , $this->getEnvironment () |
|
72 | + realpath($frameworkIni), $this->getEnvironment() |
|
73 | 73 | ); |
74 | 74 | |
75 | - $arrConfig = $objConfig->toArray (); |
|
75 | + $arrConfig = $objConfig->toArray(); |
|
76 | 76 | |
77 | - if ( isset( $arrConfig[ 'resources' ][ 'db' ] ) ) |
|
77 | + if (isset($arrConfig['resources']['db'])) |
|
78 | 78 | { |
79 | - $this->config = $arrConfig[ 'resources' ][ 'db' ]; |
|
79 | + $this->config = $arrConfig['resources']['db']; |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
@@ -85,27 +85,27 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return \Classes\AdapterMakerFile\AbstractAdapter[] |
87 | 87 | */ |
88 | - public function getMakeFileInstances () |
|
88 | + public function getMakeFileInstances() |
|
89 | 89 | { |
90 | 90 | |
91 | - $instances = array (); |
|
92 | - if ( $this->hasOptionalClasses () ) |
|
91 | + $instances = array(); |
|
92 | + if ($this->hasOptionalClasses()) |
|
93 | 93 | { |
94 | - foreach ( $this->getOptionalClasses () as $optionalClass ) |
|
94 | + foreach ($this->getOptionalClasses() as $optionalClass) |
|
95 | 95 | { |
96 | - $Name = ucfirst ( $optionalClass ); |
|
96 | + $Name = ucfirst($optionalClass); |
|
97 | 97 | $className = "Classes\\AdapterMakerFile\\ZendFrameworkOne\\{$Name}"; |
98 | - if(method_exists($className,'getInstance')){ |
|
99 | - $instances[] = $className::getInstance (); |
|
98 | + if (method_exists($className, 'getInstance')) { |
|
99 | + $instances[] = $className::getInstance(); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | - return array_merge ( array ( |
|
105 | - DbTable::getInstance () , |
|
106 | - Entity::getInstance () , |
|
107 | - Model::getInstance () |
|
108 | - ) , $instances ); |
|
104 | + return array_merge(array( |
|
105 | + DbTable::getInstance(), |
|
106 | + Entity::getInstance(), |
|
107 | + Model::getInstance() |
|
108 | + ), $instances); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | } |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | /** |
219 | 219 | * Retorna o Nome da Sequence da tabela |
220 | 220 | * |
221 | - * @param $table |
|
221 | + * @param string $table |
|
222 | 222 | * @param $column |
223 | 223 | * |
224 | 224 | * @return string |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * @param $nameTable |
270 | 270 | * @param int $schema |
271 | 271 | * |
272 | - * @return \Classes\Db\DbTable |
|
272 | + * @return AbsractAdapter |
|
273 | 273 | */ |
274 | 274 | public function createTable ( $nameTable , $schema = 0 ) |
275 | 275 | { |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | |
330 | 330 | /** |
331 | 331 | * @param string $nameTable |
332 | - * @param int|string $schema |
|
332 | + * @param integer $schema |
|
333 | 333 | * |
334 | 334 | * @return bool |
335 | 335 | */ |
@@ -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[ strtoupper($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,37 +174,37 @@ 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 | 'column_default' => $table ['column_default'] |
201 | 201 | ) |
202 | 202 | ); |
203 | 203 | |
204 | - $this->getTable ( $key , $schema ) |
|
205 | - ->addColumn ( $column ) |
|
206 | - ->setNamespace ( |
|
207 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
204 | + $this->getTable($key, $schema) |
|
205 | + ->addColumn($column) |
|
206 | + ->setNamespace( |
|
207 | + $this->config->createClassNamespace($this->getTable($key, $schema)) |
|
208 | 208 | ); |
209 | 209 | } |
210 | 210 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @return int |
216 | 216 | */ |
217 | - abstract public function getTotalTables (); |
|
217 | + abstract public function getTotalTables(); |
|
218 | 218 | |
219 | 219 | /** |
220 | 220 | * Retorna o Nome da Sequence da tabela |
@@ -224,33 +224,33 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @return string |
226 | 226 | */ |
227 | - abstract public function getSequence ( $table , $column , $schema = 0 ); |
|
227 | + abstract public function getSequence($table, $column, $schema = 0); |
|
228 | 228 | |
229 | 229 | /** |
230 | 230 | * @return array |
231 | 231 | */ |
232 | - abstract public function getListConstrant (); |
|
232 | + abstract public function getListConstrant(); |
|
233 | 233 | |
234 | 234 | /** |
235 | 235 | * @param string $str |
236 | 236 | * |
237 | 237 | * @return string |
238 | 238 | */ |
239 | - protected function convertTypeToPhp ( $str ) |
|
239 | + protected function convertTypeToPhp($str) |
|
240 | 240 | { |
241 | - if ( isset( $this->dataTypesToPhp[ $str ] ) ) |
|
241 | + if (isset($this->dataTypesToPhp[$str])) |
|
242 | 242 | { |
243 | - return $this->dataTypesToPhp[ $str ]; |
|
243 | + return $this->dataTypesToPhp[$str]; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return 'string'; |
247 | 247 | } |
248 | 248 | |
249 | - protected function convertTypeToSimple ( $str ) |
|
249 | + protected function convertTypeToSimple($str) |
|
250 | 250 | { |
251 | - if ( isset( $this->dataTypesToSimple[ $str ] ) ) |
|
251 | + if (isset($this->dataTypesToSimple[$str])) |
|
252 | 252 | { |
253 | - return $this->dataTypesToSimple[ $str ]; |
|
253 | + return $this->dataTypesToSimple[$str]; |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | return 'string'; |
@@ -259,12 +259,12 @@ discard block |
||
259 | 259 | /** |
260 | 260 | * @return string |
261 | 261 | */ |
262 | - abstract public function getPDOString (); |
|
262 | + abstract public function getPDOString(); |
|
263 | 263 | |
264 | 264 | /** |
265 | 265 | * @return string |
266 | 266 | */ |
267 | - abstract public function getPDOSocketString (); |
|
267 | + abstract public function getPDOSocketString(); |
|
268 | 268 | |
269 | 269 | /** |
270 | 270 | * @param $nameTable |
@@ -272,18 +272,18 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return \Classes\Db\DbTable |
274 | 274 | */ |
275 | - public function createTable ( $nameTable , $schema = 0 ) |
|
275 | + public function createTable($nameTable, $schema = 0) |
|
276 | 276 | { |
277 | - if ( ! isset( $this->objDbTables[ strtoupper($schema) ] ) ) |
|
277 | + if ( ! isset($this->objDbTables[strtoupper($schema)])) |
|
278 | 278 | { |
279 | - $this->objDbTables[ strtoupper($schema) ] = new DbTables(); |
|
279 | + $this->objDbTables[strtoupper($schema)] = new DbTables(); |
|
280 | 280 | } |
281 | 281 | |
282 | - $this->objDbTables[ strtoupper($schema) ][ trim ( $nameTable ) ] = DbTable::getInstance () |
|
283 | - ->populate ( |
|
284 | - array ( |
|
285 | - 'table' => $nameTable , |
|
286 | - 'schema' => $schema , |
|
282 | + $this->objDbTables[strtoupper($schema)][trim($nameTable)] = DbTable::getInstance() |
|
283 | + ->populate( |
|
284 | + array( |
|
285 | + 'table' => $nameTable, |
|
286 | + 'schema' => $schema, |
|
287 | 287 | 'database' => $this->database |
288 | 288 | ) |
289 | 289 | ); |
@@ -296,24 +296,24 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @return \Classes\Db\Iterators\DbTables |
298 | 298 | */ |
299 | - public function getTables ( $schema = 0 ) |
|
299 | + public function getTables($schema = 0) |
|
300 | 300 | { |
301 | - if ( ! isset( $this->objDbTables[ strtoupper($schema) ] ) ) |
|
301 | + if ( ! isset($this->objDbTables[strtoupper($schema)])) |
|
302 | 302 | { |
303 | - return array (); |
|
303 | + return array(); |
|
304 | 304 | } |
305 | 305 | |
306 | - return $this->objDbTables[ strtoupper($schema) ]; |
|
306 | + return $this->objDbTables[strtoupper($schema)]; |
|
307 | 307 | } |
308 | 308 | |
309 | - public function getAllTables () |
|
309 | + public function getAllTables() |
|
310 | 310 | { |
311 | 311 | return $this->objDbTables; |
312 | 312 | } |
313 | 313 | |
314 | - public function hasTables () |
|
314 | + public function hasTables() |
|
315 | 315 | { |
316 | - return ! empty( $this->objDbTables ); |
|
316 | + return ! empty($this->objDbTables); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -323,9 +323,9 @@ discard block |
||
323 | 323 | * |
324 | 324 | * @return \Classes\Db\DbTable |
325 | 325 | */ |
326 | - public function getTable ( $nameTable , $schema = 0 ) |
|
326 | + public function getTable($nameTable, $schema = 0) |
|
327 | 327 | { |
328 | - return $this->objDbTables[ strtoupper($schema) ][ trim ( $nameTable ) ]; |
|
328 | + return $this->objDbTables[strtoupper($schema)][trim($nameTable)]; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -334,9 +334,9 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @return bool |
336 | 336 | */ |
337 | - public function hasTable ( $nameTable , $schema = 0 ) |
|
337 | + public function hasTable($nameTable, $schema = 0) |
|
338 | 338 | { |
339 | - return isset( $this->objDbTables[ strtoupper($schema) ][ trim ( $nameTable ) ] ); |
|
339 | + return isset($this->objDbTables[strtoupper($schema)][trim($nameTable)]); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
@@ -344,66 +344,66 @@ discard block |
||
344 | 344 | * |
345 | 345 | * @return array[] |
346 | 346 | */ |
347 | - abstract public function getListColumns (); |
|
347 | + abstract public function getListColumns(); |
|
348 | 348 | |
349 | 349 | /** |
350 | 350 | * Retorna um Array com nome das tabelas |
351 | 351 | * |
352 | 352 | * @return string[] |
353 | 353 | */ |
354 | - abstract public function getListNameTable (); |
|
354 | + abstract public function getListNameTable(); |
|
355 | 355 | |
356 | 356 | /** |
357 | 357 | * @param \Classes\AdapterConfig\AbstractAdapter $adapterConfig |
358 | 358 | */ |
359 | - public function __construct ( AbstractAdapter $adapterConfig ) |
|
359 | + public function __construct(AbstractAdapter $adapterConfig) |
|
360 | 360 | { |
361 | 361 | $this->config = $adapterConfig; |
362 | - $this->host = $adapterConfig->getHost (); |
|
363 | - $this->database = $adapterConfig->getDatabase (); |
|
364 | - $this->port = $adapterConfig->hasPort () ? $adapterConfig->getPort () |
|
362 | + $this->host = $adapterConfig->getHost(); |
|
363 | + $this->database = $adapterConfig->getDatabase(); |
|
364 | + $this->port = $adapterConfig->hasPort() ? $adapterConfig->getPort() |
|
365 | 365 | : $this->port; |
366 | - $this->username = $adapterConfig->getUser (); |
|
367 | - $this->password = $adapterConfig->getPassword (); |
|
368 | - $this->socket = $adapterConfig->getSocket (); |
|
369 | - $this->tablesName = $adapterConfig->hasTablesName () |
|
370 | - ? $adapterConfig->getListTablesName () : ''; |
|
366 | + $this->username = $adapterConfig->getUser(); |
|
367 | + $this->password = $adapterConfig->getPassword(); |
|
368 | + $this->socket = $adapterConfig->getSocket(); |
|
369 | + $this->tablesName = $adapterConfig->hasTablesName() |
|
370 | + ? $adapterConfig->getListTablesName() : ''; |
|
371 | 371 | |
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
375 | 375 | * Executa as consultas do banco de dados |
376 | 376 | */ |
377 | - public function runDatabase () |
|
377 | + public function runDatabase() |
|
378 | 378 | { |
379 | - $this->parseTables (); |
|
380 | - $this->parseConstrants (); |
|
379 | + $this->parseTables(); |
|
380 | + $this->parseConstrants(); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
384 | 384 | * |
385 | 385 | * @return \PDO |
386 | 386 | */ |
387 | - public function getPDO () |
|
387 | + public function getPDO() |
|
388 | 388 | { |
389 | - if ( is_null ( $this->_pdo ) ) |
|
389 | + if (is_null($this->_pdo)) |
|
390 | 390 | { |
391 | - if ( ! empty( $this->socket ) ) |
|
391 | + if ( ! empty($this->socket)) |
|
392 | 392 | { |
393 | - $pdoString = $this->getPDOSocketString (); |
|
393 | + $pdoString = $this->getPDOSocketString(); |
|
394 | 394 | } else |
395 | 395 | { |
396 | - $pdoString = $this->getPDOString (); |
|
396 | + $pdoString = $this->getPDOString(); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | try |
400 | 400 | { |
401 | - $this->_pdo = new \PDO ( |
|
402 | - $pdoString , $this->username , $this->password |
|
401 | + $this->_pdo = new \PDO( |
|
402 | + $pdoString, $this->username, $this->password |
|
403 | 403 | ); |
404 | - } catch ( \Exception $e ) |
|
404 | + } catch (\Exception $e) |
|
405 | 405 | { |
406 | - die ( "\033[0;31mPDO error: " . $e->getMessage () . "\033[0m\n" ); |
|
406 | + die ("\033[0;31mPDO error: " . $e->getMessage() . "\033[0m\n"); |
|
407 | 407 | } |
408 | 408 | } |
409 | 409 |