@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | { |
| 89 | 89 | foreach ( $arrFoldersName as $index => $folderName ) { |
| 90 | 90 | $arrFoldersName[ $index ] = $this->getConfig () |
| 91 | - ->replaceReservedWord ( $folderName ); |
|
| 91 | + ->replaceReservedWord ( $folderName ); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | return implode ( DIRECTORY_SEPARATOR, array_filter ( $arrFoldersName ) ); |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | $folderName, |
| 143 | 143 | $this->getClassName ( |
| 144 | 144 | $this->getConfig () |
| 145 | - ->getDatabase () |
|
| 145 | + ->getDatabase () |
|
| 146 | 146 | ) |
| 147 | 147 | ); |
| 148 | 148 | $this->location = array ( $this->filterLocation ( $url ) ); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @return String |
| 276 | 276 | */ |
| 277 | 277 | protected function getParsedTplContents ( $tplFile, $vars = array (), \Classes\Db\DbTable $objTables = null, |
| 278 | - $objMakeFile = null |
|
| 278 | + $objMakeFile = null |
|
| 279 | 279 | ) { |
| 280 | 280 | |
| 281 | 281 | $arrUrl = array ( |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * @type string[] |
| 20 | 20 | */ |
| 21 | - public $location = array (); |
|
| 21 | + public $location = array(); |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * caminho de pastas Base |
@@ -39,42 +39,42 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | private $msgReservedWord = "\033[0mPlease enter the value for reserved word \033[0;31m'%index%' \033[1;33m[%config%]:\033[0m "; |
| 41 | 41 | |
| 42 | - public function __construct ( Config $config ) |
|
| 42 | + public function __construct(Config $config) |
|
| 43 | 43 | { |
| 44 | - $this->config = $config->getAdapterConfig (); |
|
| 45 | - $this->parseReservedWord ( $this->getConfig () ); |
|
| 46 | - $this->driver = $config->getAdapterDriver ( $this->getConfig () ); |
|
| 47 | - $this->parseLocation ( $config->_basePath ); |
|
| 44 | + $this->config = $config->getAdapterConfig(); |
|
| 45 | + $this->parseReservedWord($this->getConfig()); |
|
| 46 | + $this->driver = $config->getAdapterDriver($this->getConfig()); |
|
| 47 | + $this->parseLocation($config->_basePath); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * @param AdapterConfig\AbstractAdapter $config |
| 52 | 52 | */ |
| 53 | - public function parseReservedWord ( AdapterConfig\AbstractAdapter $config ) |
|
| 53 | + public function parseReservedWord(AdapterConfig\AbstractAdapter $config) |
|
| 54 | 54 | { |
| 55 | 55 | $palavrasReservadas = $config->reservedWord; |
| 56 | - if ( !$palavrasReservadas ) { |
|
| 56 | + if ( ! $palavrasReservadas) { |
|
| 57 | 57 | return; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $schema = $config->getSchemas (); |
|
| 61 | - $db = $config->getDatabase (); |
|
| 62 | - $hasSchema = array_intersect ( $schema, array_flip ( $palavrasReservadas ) ); |
|
| 63 | - $hasDatabase = in_array ( $db, $palavrasReservadas ); |
|
| 64 | - if ( !( $hasSchema or $hasDatabase ) ) { |
|
| 60 | + $schema = $config->getSchemas(); |
|
| 61 | + $db = $config->getDatabase(); |
|
| 62 | + $hasSchema = array_intersect($schema, array_flip($palavrasReservadas)); |
|
| 63 | + $hasDatabase = in_array($db, $palavrasReservadas); |
|
| 64 | + if ( ! ($hasSchema or $hasDatabase)) { |
|
| 65 | 65 | return; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | echo "- database has reserved words\n"; |
| 69 | - foreach ( $palavrasReservadas as $index => $config ) { |
|
| 70 | - $attribs = array ( |
|
| 69 | + foreach ($palavrasReservadas as $index => $config) { |
|
| 70 | + $attribs = array( |
|
| 71 | 71 | "%index%" => $index, |
| 72 | 72 | "%config%" => $config |
| 73 | 73 | ); |
| 74 | - echo strtr ( $this->msgReservedWord, $attribs ); |
|
| 75 | - $line = trim ( fgets ( STDIN ) ); |
|
| 76 | - if ( !empty( $line ) ) { |
|
| 77 | - $this->getConfig()->reservedWord[ $index ] = $line; |
|
| 74 | + echo strtr($this->msgReservedWord, $attribs); |
|
| 75 | + $line = trim(fgets(STDIN)); |
|
| 76 | + if ( ! empty($line)) { |
|
| 77 | + $this->getConfig()->reservedWord[$index] = $line; |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -84,156 +84,156 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @return string |
| 86 | 86 | */ |
| 87 | - private function filterLocation ( $arrFoldersName ) |
|
| 87 | + private function filterLocation($arrFoldersName) |
|
| 88 | 88 | { |
| 89 | - foreach ( $arrFoldersName as $index => $folderName ) { |
|
| 90 | - $arrFoldersName[ $index ] = $this->getConfig () |
|
| 91 | - ->replaceReservedWord ( $folderName ); |
|
| 89 | + foreach ($arrFoldersName as $index => $folderName) { |
|
| 90 | + $arrFoldersName[$index] = $this->getConfig() |
|
| 91 | + ->replaceReservedWord($folderName); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - return implode ( DIRECTORY_SEPARATOR, array_filter ( $arrFoldersName ) ); |
|
| 94 | + return implode(DIRECTORY_SEPARATOR, array_filter($arrFoldersName)); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | 98 | * Analisa os caminhos das pastas base |
| 99 | 99 | */ |
| 100 | - public function parseLocation ( $basePath ) |
|
| 100 | + public function parseLocation($basePath) |
|
| 101 | 101 | { |
| 102 | 102 | |
| 103 | - $arrBase = array ( |
|
| 103 | + $arrBase = array( |
|
| 104 | 104 | $basePath, |
| 105 | 105 | $this->config->path |
| 106 | 106 | ); |
| 107 | 107 | |
| 108 | - $this->baseLocation = $this->filterLocation ( $arrBase ); |
|
| 108 | + $this->baseLocation = $this->filterLocation($arrBase); |
|
| 109 | 109 | |
| 110 | 110 | # pasta com nome do driver do banco |
| 111 | 111 | $driverBase = ''; |
| 112 | - if ( (bool) @$this->config->{"folder-database"} ) { |
|
| 113 | - $classDriver = explode ( '\\', get_class ( $this->driver ) ); |
|
| 114 | - $driverBase = end ( $classDriver ); |
|
| 112 | + if ((bool) @$this->config->{"folder-database"} ) { |
|
| 113 | + $classDriver = explode('\\', get_class($this->driver)); |
|
| 114 | + $driverBase = end($classDriver); |
|
| 115 | 115 | } |
| 116 | 116 | $folderName = ''; |
| 117 | - if ( (bool) @$this->config->{"folder-name"} ) { |
|
| 118 | - $folderName = $this->getClassName ( trim ( $this->config->{"folder-name"} ) ); |
|
| 117 | + if ((bool) @$this->config->{"folder-name"} ) { |
|
| 118 | + $folderName = $this->getClassName(trim($this->config->{"folder-name"} )); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - if ( $this->config->hasSchemas () ) { |
|
| 121 | + if ($this->config->hasSchemas()) { |
|
| 122 | 122 | |
| 123 | - $schemas = $this->config->getSchemas (); |
|
| 124 | - foreach ( $schemas as $schema ) { |
|
| 125 | - $arrUrl = array ( |
|
| 123 | + $schemas = $this->config->getSchemas(); |
|
| 124 | + foreach ($schemas as $schema) { |
|
| 125 | + $arrUrl = array( |
|
| 126 | 126 | $this->baseLocation, |
| 127 | 127 | $driverBase, |
| 128 | 128 | $folderName, |
| 129 | - $this->getClassName ( $schema ) |
|
| 129 | + $this->getClassName($schema) |
|
| 130 | 130 | ); |
| 131 | 131 | |
| 132 | - $this->location[ $schema ] = $this->filterLocation ( $arrUrl ); |
|
| 133 | - unset( $arrUrl ); |
|
| 132 | + $this->location[$schema] = $this->filterLocation($arrUrl); |
|
| 133 | + unset($arrUrl); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
| 137 | 137 | } |
| 138 | 138 | else { |
| 139 | - $url = array ( |
|
| 139 | + $url = array( |
|
| 140 | 140 | $this->baseLocation, |
| 141 | 141 | $driverBase, |
| 142 | 142 | $folderName, |
| 143 | - $this->getClassName ( |
|
| 144 | - $this->getConfig () |
|
| 145 | - ->getDatabase () |
|
| 143 | + $this->getClassName( |
|
| 144 | + $this->getConfig() |
|
| 145 | + ->getDatabase() |
|
| 146 | 146 | ) |
| 147 | 147 | ); |
| 148 | - $this->location = array ( $this->filterLocation ( $url ) ); |
|
| 149 | - unset( $url ); |
|
| 148 | + $this->location = array($this->filterLocation($url)); |
|
| 149 | + unset($url); |
|
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
| 154 | 154 | * @return AdapterConfig\AbstractAdapter |
| 155 | 155 | */ |
| 156 | - public function getConfig () |
|
| 156 | + public function getConfig() |
|
| 157 | 157 | { |
| 158 | 158 | return $this->config; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /* Get current time */ |
| 162 | - public function startTime () |
|
| 162 | + public function startTime() |
|
| 163 | 163 | { |
| 164 | 164 | echo "Starting..\n"; |
| 165 | - $this->startTime = microtime ( true ); |
|
| 165 | + $this->startTime = microtime(true); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - private function getRunTime () |
|
| 168 | + private function getRunTime() |
|
| 169 | 169 | { |
| 170 | - return round ( ( microtime ( true ) - $this->startTime ), 3 ); |
|
| 170 | + return round((microtime(true) - $this->startTime), 3); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
| 174 | 174 | * Executa o Make, criando arquivos e Diretorios |
| 175 | 175 | */ |
| 176 | - public function run () |
|
| 176 | + public function run() |
|
| 177 | 177 | { |
| 178 | - $this->startTime (); |
|
| 179 | - $this->driver->runDatabase (); |
|
| 180 | - $countSchema = count ( $this->location ); |
|
| 181 | - $max = $this->driver->getTotalTables () * ( $countSchema * $this->countDiretory () ); |
|
| 178 | + $this->startTime(); |
|
| 179 | + $this->driver->runDatabase(); |
|
| 180 | + $countSchema = count($this->location); |
|
| 181 | + $max = $this->driver->getTotalTables() * ($countSchema * $this->countDiretory()); |
|
| 182 | 182 | $cur = 0; |
| 183 | 183 | |
| 184 | 184 | |
| 185 | - foreach ( $this->location as $schema => $location ) { |
|
| 186 | - foreach ( $this->factoryMakerFile () as $objMakeFile ) { |
|
| 187 | - $path = $location . DIRECTORY_SEPARATOR . $objMakeFile->getPastName (); |
|
| 188 | - self::makeDir ( $path ); |
|
| 185 | + foreach ($this->location as $schema => $location) { |
|
| 186 | + foreach ($this->factoryMakerFile() as $objMakeFile) { |
|
| 187 | + $path = $location . DIRECTORY_SEPARATOR . $objMakeFile->getPastName(); |
|
| 188 | + self::makeDir($path); |
|
| 189 | 189 | |
| 190 | - if ( $objMakeFile->getParentFileTpl () != '' ) { |
|
| 190 | + if ($objMakeFile->getParentFileTpl() != '') { |
|
| 191 | 191 | $fileAbstract = $this->baseLocation |
| 192 | 192 | . DIRECTORY_SEPARATOR |
| 193 | - . $objMakeFile->getParentClass () |
|
| 193 | + . $objMakeFile->getParentClass() |
|
| 194 | 194 | . '.php'; |
| 195 | 195 | |
| 196 | - $tplAbstract = $this->getParsedTplContents ( $objMakeFile->getParentFileTpl () ); |
|
| 197 | - self::makeSourcer ( $fileAbstract, $tplAbstract, $objMakeFile->isOverwrite () ); |
|
| 198 | - unset( $fileAbstract, $tplAbstract ); |
|
| 196 | + $tplAbstract = $this->getParsedTplContents($objMakeFile->getParentFileTpl()); |
|
| 197 | + self::makeSourcer($fileAbstract, $tplAbstract, $objMakeFile->isOverwrite()); |
|
| 198 | + unset($fileAbstract, $tplAbstract); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - foreach ( $this->driver->getTables ( $schema ) as $key => $objTables ) { |
|
| 202 | - $total = ceil ( $cur / $max ) * 100; |
|
| 203 | - printf ( "\r Creating: %6.2f%%", $total ); |
|
| 201 | + foreach ($this->driver->getTables($schema) as $key => $objTables) { |
|
| 202 | + $total = ceil($cur / $max) * 100; |
|
| 203 | + printf("\r Creating: %6.2f%%", $total); |
|
| 204 | 204 | $cur++; |
| 205 | 205 | |
| 206 | - $file = $path . DIRECTORY_SEPARATOR . self::getClassName ( $objTables->getName () ) . '.php'; |
|
| 206 | + $file = $path . DIRECTORY_SEPARATOR . self::getClassName($objTables->getName()) . '.php'; |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - $tpl = $this->getParsedTplContents ( |
|
| 210 | - $objMakeFile->getFileTpl (), |
|
| 211 | - $objMakeFile->parseRelation ( $this, $objTables ), |
|
| 209 | + $tpl = $this->getParsedTplContents( |
|
| 210 | + $objMakeFile->getFileTpl(), |
|
| 211 | + $objMakeFile->parseRelation($this, $objTables), |
|
| 212 | 212 | $objTables, |
| 213 | 213 | $objMakeFile |
| 214 | 214 | |
| 215 | 215 | ); |
| 216 | - self::makeSourcer ( $file, $tpl, $objMakeFile->isOverwrite () ); |
|
| 216 | + self::makeSourcer($file, $tpl, $objMakeFile->isOverwrite()); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - $this->reportProcess ( $cur ); |
|
| 222 | + $this->reportProcess($cur); |
|
| 223 | 223 | echo "\n\033[1;32mSuccessfully process finished!\n\033[0m"; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - private function reportProcess ( $countFiles ) |
|
| 226 | + private function reportProcess($countFiles) |
|
| 227 | 227 | { |
| 228 | - if ( $this->config->isStatusEnabled () ) { |
|
| 229 | - $databases = count ( $this->location ); |
|
| 230 | - $countDir = $this->countDiretory (); |
|
| 231 | - $totalTable = $this->driver->getTotalTables (); |
|
| 228 | + if ($this->config->isStatusEnabled()) { |
|
| 229 | + $databases = count($this->location); |
|
| 230 | + $countDir = $this->countDiretory(); |
|
| 231 | + $totalTable = $this->driver->getTotalTables(); |
|
| 232 | 232 | echo "\n------"; |
| 233 | - printf ( "\n\r-Files generated:%s", $countFiles ); |
|
| 234 | - printf ( "\n\r-Diretory generated:%s", $databases * $countDir ); |
|
| 235 | - printf ( "\n\r-Scanned tables:%s", $totalTable ); |
|
| 236 | - printf ( "\n\r-Execution time: %ssec", $this->getRunTime () ); |
|
| 233 | + printf("\n\r-Files generated:%s", $countFiles); |
|
| 234 | + printf("\n\r-Diretory generated:%s", $databases * $countDir); |
|
| 235 | + printf("\n\r-Scanned tables:%s", $totalTable); |
|
| 236 | + printf("\n\r-Execution time: %ssec", $this->getRunTime()); |
|
| 237 | 237 | echo "\n------"; |
| 238 | 238 | } |
| 239 | 239 | } |
@@ -243,9 +243,9 @@ discard block |
||
| 243 | 243 | * |
| 244 | 244 | * @return AbstractAdapter[] |
| 245 | 245 | */ |
| 246 | - public function factoryMakerFile () |
|
| 246 | + public function factoryMakerFile() |
|
| 247 | 247 | { |
| 248 | - return $this->config->getMakeFileInstances (); |
|
| 248 | + return $this->config->getMakeFileInstances(); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | * |
| 254 | 254 | * @return int |
| 255 | 255 | */ |
| 256 | - public function countDiretory () |
|
| 256 | + public function countDiretory() |
|
| 257 | 257 | { |
| 258 | 258 | $dir = 0; |
| 259 | - foreach ( $this->factoryMakerFile () as $abstractAdapter ) { |
|
| 260 | - if ( $abstractAdapter->hasDiretory () ) { |
|
| 259 | + foreach ($this->factoryMakerFile() as $abstractAdapter) { |
|
| 260 | + if ($abstractAdapter->hasDiretory()) { |
|
| 261 | 261 | $dir++; |
| 262 | 262 | } |
| 263 | 263 | } |
@@ -274,24 +274,24 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @return String |
| 276 | 276 | */ |
| 277 | - protected function getParsedTplContents ( $tplFile, $vars = array (), \Classes\Db\DbTable $objTables = null, |
|
| 277 | + protected function getParsedTplContents($tplFile, $vars = array(), \Classes\Db\DbTable $objTables = null, |
|
| 278 | 278 | $objMakeFile = null |
| 279 | 279 | ) { |
| 280 | 280 | |
| 281 | - $arrUrl = array ( |
|
| 281 | + $arrUrl = array( |
|
| 282 | 282 | __DIR__, |
| 283 | 283 | 'templates', |
| 284 | 284 | $this->config->framework, |
| 285 | 285 | $tplFile |
| 286 | 286 | ); |
| 287 | 287 | |
| 288 | - $filePath = implode ( DIRECTORY_SEPARATOR, filter_var_array ( $arrUrl ) ); |
|
| 288 | + $filePath = implode(DIRECTORY_SEPARATOR, filter_var_array($arrUrl)); |
|
| 289 | 289 | |
| 290 | - extract ( $vars ); |
|
| 291 | - ob_start (); |
|
| 290 | + extract($vars); |
|
| 291 | + ob_start(); |
|
| 292 | 292 | require $filePath; |
| 293 | - $data = ob_get_contents (); |
|
| 294 | - ob_end_clean (); |
|
| 293 | + $data = ob_get_contents(); |
|
| 294 | + ob_end_clean(); |
|
| 295 | 295 | |
| 296 | 296 | return $data; |
| 297 | 297 | } |
@@ -134,8 +134,7 @@ |
||
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
| 137 | - } |
|
| 138 | - else { |
|
| 137 | + } else { |
|
| 139 | 138 | $url = array ( |
| 140 | 139 | $this->baseLocation, |
| 141 | 140 | $driverBase, |