@@ -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,12 +143,12 @@ discard block |
||
| 143 | 143 | return $return; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public function checkHasNewVersion () |
|
| 146 | + public function checkHasNewVersion() |
|
| 147 | 147 | { |
| 148 | - $opts = array ( |
|
| 149 | - 'http' => array ( |
|
| 150 | - 'method' => 'GET' , |
|
| 151 | - 'header' => array ( |
|
| 148 | + $opts = array( |
|
| 149 | + 'http' => array( |
|
| 150 | + 'method' => 'GET', |
|
| 151 | + 'header' => array( |
|
| 152 | 152 | 'User-Agent: PHP' |
| 153 | 153 | ) |
| 154 | 154 | ) |
@@ -156,22 +156,22 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | try |
| 158 | 158 | { |
| 159 | - $context = stream_context_create ( $opts ); |
|
| 160 | - $tags = json_decode ( file_get_contents ( "https://api.github.com/repos/pedro151/orm-generator/tags" , false , $context ) ); |
|
| 159 | + $context = stream_context_create($opts); |
|
| 160 | + $tags = json_decode(file_get_contents("https://api.github.com/repos/pedro151/orm-generator/tags", false, $context)); |
|
| 161 | 161 | |
| 162 | - $lastVersion = preg_replace ( "/[^0-9.]/" , "" , $tags[ 0 ]->name ); |
|
| 163 | - if ( $lastVersion > static::$version ) |
|
| 162 | + $lastVersion = preg_replace("/[^0-9.]/", "", $tags[0]->name); |
|
| 163 | + if ($lastVersion > static::$version) |
|
| 164 | 164 | { |
| 165 | 165 | return "\033[0;31mThere is a new version $lastVersion available:\033[0m https://github.com/pedro151/orm-generator\n"; |
| 166 | 166 | } |
| 167 | - } catch ( \Exception $ex ){ } |
|
| 167 | + } catch (\Exception $ex) { } |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - public function getVersion () |
|
| 170 | + public function getVersion() |
|
| 171 | 171 | { |
| 172 | 172 | $version = static::$version; |
| 173 | 173 | |
| 174 | - return "ORM Generator By: Pedro Alarcao Version: $version\n".$this->checkHasNewVersion(); |
|
| 174 | + return "ORM Generator By: Pedro Alarcao Version: $version\n" . $this->checkHasNewVersion(); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -183,31 +183,31 @@ discard block |
||
| 183 | 183 | * @return array |
| 184 | 184 | * @throws \Exception |
| 185 | 185 | */ |
| 186 | - private function parseConfig ( $basePath , $argv ) |
|
| 186 | + private function parseConfig($basePath, $argv) |
|
| 187 | 187 | { |
| 188 | 188 | $this->_basePath = $basePath; |
| 189 | 189 | |
| 190 | - $configIni = isset( $argv[ 'name-ini' ] ) |
|
| 191 | - ? $argv[ 'name-ini' ] |
|
| 190 | + $configIni = isset($argv['name-ini']) |
|
| 191 | + ? $argv['name-ini'] |
|
| 192 | 192 | : $this->_basePath |
| 193 | 193 | . $this->configIniDefault; |
| 194 | 194 | |
| 195 | - $configTemp = $this->loadIniFile ( realpath ( $configIni ) ); |
|
| 196 | - $configCurrent = self::parseConfigEnv ( $configTemp , $argv ); |
|
| 195 | + $configTemp = $this->loadIniFile(realpath($configIni)); |
|
| 196 | + $configCurrent = self::parseConfigEnv($configTemp, $argv); |
|
| 197 | 197 | |
| 198 | - if ( ! isset( $configCurrent[ 'framework' ] ) ) |
|
| 198 | + if ( ! isset($configCurrent['framework'])) |
|
| 199 | 199 | { |
| 200 | - throw new \Exception( "configure which framework you want to use! \n" ); |
|
| 200 | + throw new \Exception("configure which framework you want to use! \n"); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if ( ! in_array ( $configCurrent[ 'framework' ] , $this->frameworkList ) ) |
|
| 203 | + if ( ! in_array($configCurrent['framework'], $this->frameworkList)) |
|
| 204 | 204 | { |
| 205 | - $frameworks = implode ( "\n\t" , $this->frameworkList ); |
|
| 206 | - throw new \Exception( "list of frameworks: \n\t\033[1;33m" . $frameworks |
|
| 207 | - . "\n\033[0m" ); |
|
| 205 | + $frameworks = implode("\n\t", $this->frameworkList); |
|
| 206 | + throw new \Exception("list of frameworks: \n\t\033[1;33m" . $frameworks |
|
| 207 | + . "\n\033[0m"); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - return $argv + array_filter ( $configCurrent ); |
|
| 210 | + return $argv + array_filter($configCurrent); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -217,24 +217,24 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return string |
| 219 | 219 | */ |
| 220 | - private static function parseConfigEnv ( $configTemp , $argv ) |
|
| 220 | + private static function parseConfigEnv($configTemp, $argv) |
|
| 221 | 221 | { |
| 222 | - $thisSection = isset( $configTemp[ key ( $configTemp ) ][ 'config-env' ] ) |
|
| 223 | - ? $configTemp[ key ( |
|
| 222 | + $thisSection = isset($configTemp[key($configTemp)]['config-env']) |
|
| 223 | + ? $configTemp[key( |
|
| 224 | 224 | $configTemp |
| 225 | - ) ][ 'config-env' ] : null; |
|
| 225 | + )]['config-env'] : null; |
|
| 226 | 226 | |
| 227 | - $thisSection = isset( $argv[ 'config-env' ] ) ? $argv[ 'config-env' ] |
|
| 227 | + $thisSection = isset($argv['config-env']) ? $argv['config-env'] |
|
| 228 | 228 | : $thisSection; |
| 229 | 229 | |
| 230 | - if ( isset( $configTemp[ $thisSection ][ 'extends' ] ) ) |
|
| 230 | + if (isset($configTemp[$thisSection]['extends'])) |
|
| 231 | 231 | { |
| 232 | 232 | #faz marge da config principal com a config extendida |
| 233 | - return $configTemp[ $thisSection ] |
|
| 234 | - + $configTemp[ $configTemp[ $thisSection ][ 'extends' ] ]; |
|
| 233 | + return $configTemp[$thisSection] |
|
| 234 | + + $configTemp[$configTemp[$thisSection]['extends']]; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - return $configTemp[ key ( $configTemp ) ]; |
|
| 237 | + return $configTemp[key($configTemp)]; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -248,32 +248,32 @@ discard block |
||
| 248 | 248 | * @throws \Exception |
| 249 | 249 | * @return array |
| 250 | 250 | */ |
| 251 | - protected function loadIniFile ( $filename ) |
|
| 251 | + protected function loadIniFile($filename) |
|
| 252 | 252 | { |
| 253 | - if ( ! is_file ( $filename ) ) |
|
| 253 | + if ( ! is_file($filename)) |
|
| 254 | 254 | { |
| 255 | - throw new \Exception( "\033[0;31mError: configuration file does not exist! \033[0m\n" ); |
|
| 255 | + throw new \Exception("\033[0;31mError: configuration file does not exist! \033[0m\n"); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - $loaded = parse_ini_file ( $filename , true ); |
|
| 259 | - $iniArray = array (); |
|
| 260 | - foreach ( $loaded as $key => $data ) |
|
| 258 | + $loaded = parse_ini_file($filename, true); |
|
| 259 | + $iniArray = array(); |
|
| 260 | + foreach ($loaded as $key => $data) |
|
| 261 | 261 | { |
| 262 | - $pieces = explode ( $this->sectionSeparator , $key ); |
|
| 263 | - $thisSection = trim ( $pieces[ 0 ] ); |
|
| 264 | - switch ( count ( $pieces ) ) |
|
| 262 | + $pieces = explode($this->sectionSeparator, $key); |
|
| 263 | + $thisSection = trim($pieces[0]); |
|
| 264 | + switch (count($pieces)) |
|
| 265 | 265 | { |
| 266 | 266 | case 1: |
| 267 | - $iniArray[ $thisSection ] = $data; |
|
| 267 | + $iniArray[$thisSection] = $data; |
|
| 268 | 268 | break; |
| 269 | 269 | |
| 270 | 270 | case 2: |
| 271 | - $extendedSection = trim ( $pieces[ 1 ] ); |
|
| 272 | - $iniArray[ $thisSection ] = array_merge ( array ( 'extends' => $extendedSection ) , $data ); |
|
| 271 | + $extendedSection = trim($pieces[1]); |
|
| 272 | + $iniArray[$thisSection] = array_merge(array('extends' => $extendedSection), $data); |
|
| 273 | 273 | break; |
| 274 | 274 | |
| 275 | 275 | default: |
| 276 | - throw new \Exception( "Section '$thisSection' may not extend multiple sections in $filename" ); |
|
| 276 | + throw new \Exception("Section '$thisSection' may not extend multiple sections in $filename"); |
|
| 277 | 277 | } |
| 278 | 278 | } |
| 279 | 279 | |
@@ -286,16 +286,16 @@ discard block |
||
| 286 | 286 | * @return \Classes\AdapterConfig\AbstractAdapter |
| 287 | 287 | * |
| 288 | 288 | */ |
| 289 | - private function factoryConfig () |
|
| 289 | + private function factoryConfig() |
|
| 290 | 290 | { |
| 291 | - switch ( strtolower ( $this->argv[ 'framework' ] ) ) |
|
| 291 | + switch (strtolower($this->argv['framework'])) |
|
| 292 | 292 | { |
| 293 | 293 | case 'zf1': |
| 294 | - return new ZendFrameworkOne( $this->argv ); |
|
| 294 | + return new ZendFrameworkOne($this->argv); |
|
| 295 | 295 | case 'phalcon': |
| 296 | - return new Phalcon( $this->argv ); |
|
| 296 | + return new Phalcon($this->argv); |
|
| 297 | 297 | default: |
| 298 | - return new None( $this->argv ); |
|
| 298 | + return new None($this->argv); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | } |
@@ -307,33 +307,33 @@ discard block |
||
| 307 | 307 | * |
| 308 | 308 | * @return AdaptersDriver\AbsractAdapter |
| 309 | 309 | */ |
| 310 | - private function factoryDriver ( AdapterConfig\AbstractAdapter $config ) |
|
| 310 | + private function factoryDriver(AdapterConfig\AbstractAdapter $config) |
|
| 311 | 311 | { |
| 312 | - switch ( $this->argv[ 'driver' ] ) |
|
| 312 | + switch ($this->argv['driver']) |
|
| 313 | 313 | { |
| 314 | 314 | case 'pgsql': |
| 315 | 315 | case 'pdo_pgsql': |
| 316 | - return new Pgsql( $config ); |
|
| 316 | + return new Pgsql($config); |
|
| 317 | 317 | case 'mysql': |
| 318 | 318 | case 'pdo_mysql': |
| 319 | - return new Mysql( $config ); |
|
| 319 | + return new Mysql($config); |
|
| 320 | 320 | case 'mssql': |
| 321 | - return new Mssql( $config ); |
|
| 321 | + return new Mssql($config); |
|
| 322 | 322 | case 'dblib': |
| 323 | - return new Dblib( $config ); |
|
| 323 | + return new Dblib($config); |
|
| 324 | 324 | case 'sqlsrv': |
| 325 | - return new Sqlsrv( $config ); |
|
| 325 | + return new Sqlsrv($config); |
|
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
| 330 | 330 | * @return AdapterConfig\AbstractAdapter |
| 331 | 331 | */ |
| 332 | - public function getAdapterConfig () |
|
| 332 | + public function getAdapterConfig() |
|
| 333 | 333 | { |
| 334 | - if ( ! $this->adapterConfig instanceof AbstractAdapter ) |
|
| 334 | + if ( ! $this->adapterConfig instanceof AbstractAdapter) |
|
| 335 | 335 | { |
| 336 | - $this->adapterConfig = $this->factoryConfig (); |
|
| 336 | + $this->adapterConfig = $this->factoryConfig(); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | return $this->adapterConfig; |
@@ -342,11 +342,11 @@ discard block |
||
| 342 | 342 | /** |
| 343 | 343 | * @return AdaptersDriver\AbsractAdapter |
| 344 | 344 | */ |
| 345 | - public function getAdapterDriver ( AdapterConfig\AbstractAdapter $config ) |
|
| 345 | + public function getAdapterDriver(AdapterConfig\AbstractAdapter $config) |
|
| 346 | 346 | { |
| 347 | - if ( ! $this->adapterDriver ) |
|
| 347 | + if ( ! $this->adapterDriver) |
|
| 348 | 348 | { |
| 349 | - $this->adapterDriver = $this->factoryDriver ( $config ); |
|
| 349 | + $this->adapterDriver = $this->factoryDriver($config); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | return $this->adapterDriver; |