@@ -10,13 +10,13 @@ discard block |
||
| 10 | 10 | * |
| 11 | 11 | * @param $dir |
| 12 | 12 | */ |
| 13 | - public static function makeDir ( $dir ) |
|
| 13 | + public static function makeDir($dir) |
|
| 14 | 14 | { |
| 15 | - if ( !is_dir ( $dir ) ) |
|
| 15 | + if ( ! is_dir($dir)) |
|
| 16 | 16 | { |
| 17 | - if ( !@mkdir ( $dir, 0755, true ) ) |
|
| 17 | + if ( ! @mkdir($dir, 0755, true)) |
|
| 18 | 18 | { |
| 19 | - die( "error: could not create directory $dir\n" ); |
|
| 19 | + die("error: could not create directory $dir\n"); |
|
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | } |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | * @param string $tplContent Conteudo do Template |
| 27 | 27 | * @param bool $overwrite Sobrescreve o arquivo ja existente |
| 28 | 28 | */ |
| 29 | - public static function makeSourcer ( $nameFile, $tplContent, $overwrite = false ) |
|
| 29 | + public static function makeSourcer($nameFile, $tplContent, $overwrite = false) |
|
| 30 | 30 | { |
| 31 | - if ( !$overwrite && is_file ( $nameFile ) ) |
|
| 31 | + if ( ! $overwrite && is_file($nameFile)) |
|
| 32 | 32 | { |
| 33 | 33 | return; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if ( !file_put_contents ( $nameFile, $tplContent ) ) |
|
| 36 | + if ( ! file_put_contents($nameFile, $tplContent)) |
|
| 37 | 37 | { |
| 38 | - die( "Error: could not write model file $nameFile." ); |
|
| 38 | + die("Error: could not write model file $nameFile."); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | - public static function getClassName ( $str ) |
|
| 49 | + public static function getClassName($str) |
|
| 50 | 50 | { |
| 51 | 51 | $temp = ''; |
| 52 | - foreach ( explode ( self::SEPARETOR, $str ) as $part ) |
|
| 52 | + foreach (explode(self::SEPARETOR, $str) as $part) |
|
| 53 | 53 | { |
| 54 | - $temp .= ucfirst ( $part ); |
|
| 54 | + $temp .= ucfirst($part); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | return $temp; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - protected function getParsedTplContents ( $filePath, $vars = array () ) |
|
| 60 | + protected function getParsedTplContents($filePath, $vars = array()) |
|
| 61 | 61 | { |
| 62 | - extract ( $vars ); |
|
| 63 | - ob_start (); |
|
| 62 | + extract($vars); |
|
| 63 | + ob_start(); |
|
| 64 | 64 | require $filePath; |
| 65 | - $data = ob_get_contents (); |
|
| 66 | - ob_end_clean (); |
|
| 65 | + $data = ob_get_contents(); |
|
| 66 | + ob_end_clean(); |
|
| 67 | 67 | |
| 68 | 68 | return $data; |
| 69 | 69 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | /** |
| 50 | 50 | * @var array |
| 51 | 51 | */ |
| 52 | - private $argv = array (); |
|
| 52 | + private $argv = array(); |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * @var \Classes\AdapterConfig\AbstractAdapter |
@@ -61,18 +61,18 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | private $adapterDriver; |
| 63 | 63 | |
| 64 | - public function __construct ( $argv , $basePath ) |
|
| 64 | + public function __construct($argv, $basePath) |
|
| 65 | 65 | { |
| 66 | - if ( array_key_exists ( 'help' , $argv ) ) |
|
| 66 | + if (array_key_exists('help', $argv)) |
|
| 67 | 67 | { |
| 68 | - die ( $this->getUsage () ); |
|
| 68 | + die ($this->getUsage()); |
|
| 69 | 69 | } |
| 70 | - if ( array_key_exists ( 'status' , $argv ) ) |
|
| 70 | + if (array_key_exists('status', $argv)) |
|
| 71 | 71 | { |
| 72 | - $argv[ 'status' ] = true; |
|
| 72 | + $argv['status'] = true; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $this->argv = $this->parseConfig ( $basePath , $argv ); |
|
| 75 | + $this->argv = $this->parseConfig($basePath, $argv); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return string |
| 82 | 82 | */ |
| 83 | - public function getUsage () |
|
| 83 | + public function getUsage() |
|
| 84 | 84 | { |
| 85 | 85 | $version = static::$version; |
| 86 | 86 | return <<<EOF |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | EOF; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - public function getVersion () |
|
| 107 | + public function getVersion() |
|
| 108 | 108 | { |
| 109 | 109 | $version = static::$version; |
| 110 | 110 | return "ORM-Generator By: Pedro Alarcao Version: $version"; |
@@ -119,22 +119,22 @@ discard block |
||
| 119 | 119 | * @return array |
| 120 | 120 | * @throws \Exception |
| 121 | 121 | */ |
| 122 | - private function parseConfig ( $basePath , $argv ) |
|
| 122 | + private function parseConfig($basePath, $argv) |
|
| 123 | 123 | { |
| 124 | - $this->_basePath = dirname ( $basePath ); |
|
| 124 | + $this->_basePath = dirname($basePath); |
|
| 125 | 125 | |
| 126 | - $configIni = isset( $argv[ 'config-ini' ] ) ? $argv[ 'config-ini' ] |
|
| 126 | + $configIni = isset($argv['config-ini']) ? $argv['config-ini'] |
|
| 127 | 127 | : $this->_basePath . $this->configIniDefault; |
| 128 | 128 | |
| 129 | - $configTemp = $this->loadIniFile ( realpath ( $configIni ) ); |
|
| 130 | - $configCurrent = $this->parseConfigEnv ( $configTemp , $argv ); |
|
| 129 | + $configTemp = $this->loadIniFile(realpath($configIni)); |
|
| 130 | + $configCurrent = $this->parseConfigEnv($configTemp, $argv); |
|
| 131 | 131 | |
| 132 | - if ( ! isset( $configCurrent[ 'framework' ] ) ) |
|
| 132 | + if ( ! isset($configCurrent['framework'])) |
|
| 133 | 133 | { |
| 134 | - throw new \Exception( "configure which framework you want to use! \n" ); |
|
| 134 | + throw new \Exception("configure which framework you want to use! \n"); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - return $argv + array_filter ( $configCurrent ); |
|
| 137 | + return $argv + array_filter($configCurrent); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -144,27 +144,27 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @return string |
| 146 | 146 | */ |
| 147 | - public function parseConfigEnv ( $configTemp , $argv ) |
|
| 147 | + public function parseConfigEnv($configTemp, $argv) |
|
| 148 | 148 | { |
| 149 | - if ( isset( $configTemp[ key ( $configTemp ) ][ 'config-env' ] ) |
|
| 150 | - or isset( $argv[ 'config-env' ] ) |
|
| 149 | + if (isset($configTemp[key($configTemp)]['config-env']) |
|
| 150 | + or isset($argv['config-env']) |
|
| 151 | 151 | ) |
| 152 | 152 | { |
| 153 | - $thisSection = isset( $argv[ 'config-env' ] ) |
|
| 153 | + $thisSection = isset($argv['config-env']) |
|
| 154 | 154 | ? |
| 155 | - $argv[ 'config-env' ] |
|
| 155 | + $argv['config-env'] |
|
| 156 | 156 | : |
| 157 | - $configTemp[ key ( $configTemp ) ][ 'config-env' ]; |
|
| 157 | + $configTemp[key($configTemp)]['config-env']; |
|
| 158 | 158 | |
| 159 | 159 | |
| 160 | - if ( isset( $configTemp[ $thisSection ][ 'extends' ] ) ) |
|
| 160 | + if (isset($configTemp[$thisSection]['extends'])) |
|
| 161 | 161 | { |
| 162 | - return $configTemp[ $thisSection ] |
|
| 163 | - + $configTemp[ $configTemp[ $thisSection ][ 'extends' ] ]; |
|
| 162 | + return $configTemp[$thisSection] |
|
| 163 | + + $configTemp[$configTemp[$thisSection]['extends']]; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - return $configTemp[ key ( $configTemp ) ]; |
|
| 167 | + return $configTemp[key($configTemp)]; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -178,32 +178,32 @@ discard block |
||
| 178 | 178 | * @throws \Exception |
| 179 | 179 | * @return array |
| 180 | 180 | */ |
| 181 | - protected function loadIniFile ( $filename ) |
|
| 181 | + protected function loadIniFile($filename) |
|
| 182 | 182 | { |
| 183 | - if ( ! is_file ( $filename ) ) |
|
| 183 | + if ( ! is_file($filename)) |
|
| 184 | 184 | { |
| 185 | - throw new \Exception( "configuration file does not exist! \n" ); |
|
| 185 | + throw new \Exception("configuration file does not exist! \n"); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - $loaded = parse_ini_file ( $filename , true ); |
|
| 189 | - $iniArray = array (); |
|
| 190 | - foreach ( $loaded as $key => $data ) |
|
| 188 | + $loaded = parse_ini_file($filename, true); |
|
| 189 | + $iniArray = array(); |
|
| 190 | + foreach ($loaded as $key => $data) |
|
| 191 | 191 | { |
| 192 | - $pieces = explode ( $this->sectionSeparator , $key ); |
|
| 193 | - $thisSection = trim ( $pieces[ 0 ] ); |
|
| 194 | - switch ( count ( $pieces ) ) |
|
| 192 | + $pieces = explode($this->sectionSeparator, $key); |
|
| 193 | + $thisSection = trim($pieces[0]); |
|
| 194 | + switch (count($pieces)) |
|
| 195 | 195 | { |
| 196 | 196 | case 1: |
| 197 | - $iniArray[ $thisSection ] = $data; |
|
| 197 | + $iniArray[$thisSection] = $data; |
|
| 198 | 198 | break; |
| 199 | 199 | |
| 200 | 200 | case 2: |
| 201 | - $extendedSection = trim ( $pieces[ 1 ] ); |
|
| 202 | - $iniArray[ $thisSection ] = array_merge ( array ( 'extends' => $extendedSection ) , $data ); |
|
| 201 | + $extendedSection = trim($pieces[1]); |
|
| 202 | + $iniArray[$thisSection] = array_merge(array('extends' => $extendedSection), $data); |
|
| 203 | 203 | break; |
| 204 | 204 | |
| 205 | 205 | default: |
| 206 | - throw new \Exception( "Section '$thisSection' may not extend multiple sections in $filename" ); |
|
| 206 | + throw new \Exception("Section '$thisSection' may not extend multiple sections in $filename"); |
|
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | |
@@ -214,15 +214,15 @@ discard block |
||
| 214 | 214 | * analisa a opção e cria a instancia do Atapter do determinado framework |
| 215 | 215 | * |
| 216 | 216 | */ |
| 217 | - private function factoryConfig () |
|
| 217 | + private function factoryConfig() |
|
| 218 | 218 | { |
| 219 | - switch ( strtolower ( $this->argv[ 'framework' ] ) ) |
|
| 219 | + switch (strtolower($this->argv['framework'])) |
|
| 220 | 220 | { |
| 221 | 221 | case 'none': |
| 222 | - $this->adapterConfig = new None( $this->argv ); |
|
| 222 | + $this->adapterConfig = new None($this->argv); |
|
| 223 | 223 | break; |
| 224 | 224 | case 'zend_framework': |
| 225 | - $this->adapterConfig = new ZendFrameworkOne( $this->argv ); |
|
| 225 | + $this->adapterConfig = new ZendFrameworkOne($this->argv); |
|
| 226 | 226 | break; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -232,26 +232,26 @@ discard block |
||
| 232 | 232 | * Analisa a opção e instancia o determinado banco de dados |
| 233 | 233 | * |
| 234 | 234 | */ |
| 235 | - private function factoryDriver () |
|
| 235 | + private function factoryDriver() |
|
| 236 | 236 | { |
| 237 | - switch ( $this->argv[ 'driver' ] ) |
|
| 237 | + switch ($this->argv['driver']) |
|
| 238 | 238 | { |
| 239 | 239 | case 'pgsql': |
| 240 | 240 | case 'pdo_pgsql': |
| 241 | - $this->adapterDriver = new Pgsql( $this->getAdapterConfig () ); |
|
| 241 | + $this->adapterDriver = new Pgsql($this->getAdapterConfig()); |
|
| 242 | 242 | break; |
| 243 | 243 | case 'mysql': |
| 244 | 244 | case 'pdo_mysql': |
| 245 | - $this->adapterDriver = new Mysql( $this->getAdapterConfig () ); |
|
| 245 | + $this->adapterDriver = new Mysql($this->getAdapterConfig()); |
|
| 246 | 246 | break; |
| 247 | 247 | case 'mssql': |
| 248 | - $this->adapterDriver = new Mssql( $this->getAdapterConfig () ); |
|
| 248 | + $this->adapterDriver = new Mssql($this->getAdapterConfig()); |
|
| 249 | 249 | break; |
| 250 | 250 | case 'dblib': |
| 251 | - $this->adapterDriver = new Dblib( $this->getAdapterConfig () ); |
|
| 251 | + $this->adapterDriver = new Dblib($this->getAdapterConfig()); |
|
| 252 | 252 | break; |
| 253 | 253 | case 'sqlsrv': |
| 254 | - $this->adapterDriver = new Sqlsrv( $this->getAdapterConfig () ); |
|
| 254 | + $this->adapterDriver = new Sqlsrv($this->getAdapterConfig()); |
|
| 255 | 255 | break; |
| 256 | 256 | } |
| 257 | 257 | |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | /** |
| 261 | 261 | * @return AdapterConfig\AbstractAdapter |
| 262 | 262 | */ |
| 263 | - public function getAdapterConfig () |
|
| 263 | + public function getAdapterConfig() |
|
| 264 | 264 | { |
| 265 | - if ( ! $this->adapterConfig ) |
|
| 265 | + if ( ! $this->adapterConfig) |
|
| 266 | 266 | { |
| 267 | - $this->factoryConfig (); |
|
| 267 | + $this->factoryConfig(); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | return $this->adapterConfig; |
@@ -273,11 +273,11 @@ discard block |
||
| 273 | 273 | /** |
| 274 | 274 | * @return AdaptersDriver\AbsractAdapter |
| 275 | 275 | */ |
| 276 | - public function getAdapterDriver () |
|
| 276 | + public function getAdapterDriver() |
|
| 277 | 277 | { |
| 278 | - if ( ! $this->adapterDriver ) |
|
| 278 | + if ( ! $this->adapterDriver) |
|
| 279 | 279 | { |
| 280 | - $this->factoryDriver (); |
|
| 280 | + $this->factoryDriver(); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | return $this->adapterDriver; |
@@ -1,32 +1,32 @@ |
||
| 1 | 1 | <?php |
| 2 | -define ( 'PREFIX', 'orm-generator' ); |
|
| 3 | -define ( 'PHAR_FILE', PREFIX . '.phar' ); |
|
| 4 | -define ( 'PHAR_OUTPUT', 'bin' . DIRECTORY_SEPARATOR . PHAR_FILE ); |
|
| 5 | -define ( 'DEFAULT_STUB', 'phar-generate.php' ); |
|
| 6 | -define ( 'BUILD_DIR', realpath ( __DIR__ . '/build' ) ); |
|
| 7 | -define ( 'INCLUDE_EXTENSION', '/\.php$/' ); |
|
| 2 | +define('PREFIX', 'orm-generator'); |
|
| 3 | +define('PHAR_FILE', PREFIX . '.phar'); |
|
| 4 | +define('PHAR_OUTPUT', 'bin' . DIRECTORY_SEPARATOR . PHAR_FILE); |
|
| 5 | +define('DEFAULT_STUB', 'phar-generate.php'); |
|
| 6 | +define('BUILD_DIR', realpath(__DIR__ . '/build')); |
|
| 7 | +define('INCLUDE_EXTENSION', '/\.php$/'); |
|
| 8 | 8 | |
| 9 | 9 | try |
| 10 | 10 | { |
| 11 | - if ( file_exists ( PHAR_OUTPUT ) ) |
|
| 11 | + if (file_exists(PHAR_OUTPUT)) |
|
| 12 | 12 | { |
| 13 | - unlink ( PHAR_OUTPUT ); |
|
| 13 | + unlink(PHAR_OUTPUT); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /**************************************** |
| 17 | 17 | * phar file creation |
| 18 | 18 | ****************************************/ |
| 19 | - $tarphar = new Phar( PHAR_OUTPUT ); |
|
| 20 | - $phar = $tarphar->convertToExecutable ( Phar::PHAR ); |
|
| 21 | - $phar->startBuffering (); |
|
| 22 | - $phar->buildFromDirectory ( BUILD_DIR, INCLUDE_EXTENSION ); |
|
| 23 | - $stub = $phar->createDefaultStub ( DEFAULT_STUB ); |
|
| 24 | - $phar->setStub ( "#!/usr/bin/php\n" . $stub ); |
|
| 25 | - $phar->stopBuffering (); |
|
| 19 | + $tarphar = new Phar(PHAR_OUTPUT); |
|
| 20 | + $phar = $tarphar->convertToExecutable(Phar::PHAR); |
|
| 21 | + $phar->startBuffering(); |
|
| 22 | + $phar->buildFromDirectory(BUILD_DIR, INCLUDE_EXTENSION); |
|
| 23 | + $stub = $phar->createDefaultStub(DEFAULT_STUB); |
|
| 24 | + $phar->setStub("#!/usr/bin/php\n" . $stub); |
|
| 25 | + $phar->stopBuffering(); |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | } |
| 29 | -catch ( Exception $e ) |
|
| 29 | +catch (Exception $e) |
|
| 30 | 30 | { |
| 31 | 31 | echo $e; |
| 32 | 32 | } |
| 33 | 33 | \ No newline at end of file |
@@ -25,8 +25,7 @@ |
||
| 25 | 25 | $phar->stopBuffering (); |
| 26 | 26 | |
| 27 | 27 | |
| 28 | -} |
|
| 29 | -catch ( Exception $e ) |
|
| 28 | +} catch ( Exception $e ) |
|
| 30 | 29 | { |
| 31 | 30 | echo $e; |
| 32 | 31 | } |
| 33 | 32 | \ No newline at end of file |
@@ -6,26 +6,26 @@ discard block |
||
| 6 | 6 | * @author Pedro Alarcao <[email protected]> |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! ini_get ( 'short_open_tag' ) ) |
|
| 9 | +if ( ! ini_get('short_open_tag')) |
|
| 10 | 10 | { |
| 11 | - die( "please enable short_open_tag directive in php.ini\n" ); |
|
| 11 | + die("please enable short_open_tag directive in php.ini\n"); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | -if ( ! ini_get ( 'register_argc_argv' ) ) |
|
| 14 | +if ( ! ini_get('register_argc_argv')) |
|
| 15 | 15 | { |
| 16 | - die( "please enable register_argc_argv directive in php.ini\n" ); |
|
| 16 | + die("please enable register_argc_argv directive in php.ini\n"); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
| 20 | -if ( function_exists ( 'ini_set' ) ) |
|
| 20 | +if (function_exists('ini_set')) |
|
| 21 | 21 | { |
| 22 | - @ini_set ( 'display_errors' , 1 ); |
|
| 22 | + @ini_set('display_errors', 1); |
|
| 23 | 23 | |
| 24 | - $memoryInBytes = function ( $value ) |
|
| 24 | + $memoryInBytes = function($value) |
|
| 25 | 25 | { |
| 26 | - $unit = strtolower ( substr ( $value , - 1 , 1 ) ); |
|
| 26 | + $unit = strtolower(substr($value, - 1, 1)); |
|
| 27 | 27 | $value = (int) $value; |
| 28 | - switch ( $unit ) |
|
| 28 | + switch ($unit) |
|
| 29 | 29 | { |
| 30 | 30 | case 'g': |
| 31 | 31 | $value *= 1024; |
@@ -40,21 +40,21 @@ discard block |
||
| 40 | 40 | return $value; |
| 41 | 41 | }; |
| 42 | 42 | |
| 43 | - $memoryLimit = trim ( ini_get ( 'memory_limit' ) ); |
|
| 43 | + $memoryLimit = trim(ini_get('memory_limit')); |
|
| 44 | 44 | // Increase memory_limit if it is lower than 1GB |
| 45 | - if ( $memoryLimit != - 1 && $memoryInBytes( $memoryLimit ) < 1024 * 1024 * 1024 ) |
|
| 45 | + if ($memoryLimit != - 1 && $memoryInBytes($memoryLimit) < 1024 * 1024 * 1024) |
|
| 46 | 46 | { |
| 47 | - @ini_set ( 'memory_limit' , '1G' ); |
|
| 47 | + @ini_set('memory_limit', '1G'); |
|
| 48 | 48 | } |
| 49 | - unset( $memoryInBytes , $memoryLimit ); |
|
| 49 | + unset($memoryInBytes, $memoryLimit); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | -set_include_path ( |
|
| 53 | - implode ( |
|
| 54 | - PATH_SEPARATOR , |
|
| 55 | - array ( |
|
| 56 | - realpath ( dirname ( __FILE__ ) . "/build/" ) , |
|
| 57 | - get_include_path () , |
|
| 52 | +set_include_path( |
|
| 53 | + implode( |
|
| 54 | + PATH_SEPARATOR, |
|
| 55 | + array( |
|
| 56 | + realpath(dirname(__FILE__) . "/build/"), |
|
| 57 | + get_include_path(), |
|
| 58 | 58 | ) |
| 59 | 59 | ) |
| 60 | 60 | ); |
@@ -65,34 +65,34 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | try |
| 67 | 67 | { |
| 68 | - $arrValid = array ( |
|
| 69 | - 'version' , |
|
| 70 | - 'help' , |
|
| 71 | - 'status' , |
|
| 72 | - 'init' , |
|
| 73 | - 'config-env:' , |
|
| 74 | - 'config-ini:' , |
|
| 75 | - 'database:' , |
|
| 76 | - 'schema:' , |
|
| 77 | - 'driver:' , |
|
| 78 | - 'framework:' , |
|
| 68 | + $arrValid = array( |
|
| 69 | + 'version', |
|
| 70 | + 'help', |
|
| 71 | + 'status', |
|
| 72 | + 'init', |
|
| 73 | + 'config-env:', |
|
| 74 | + 'config-ini:', |
|
| 75 | + 'database:', |
|
| 76 | + 'schema:', |
|
| 77 | + 'driver:', |
|
| 78 | + 'framework:', |
|
| 79 | 79 | 'path:' |
| 80 | 80 | ); |
| 81 | 81 | |
| 82 | - $_path = realpath ( __FILE__ ); |
|
| 83 | - $argv = getopt ( null , $arrValid ); |
|
| 82 | + $_path = realpath(__FILE__); |
|
| 83 | + $argv = getopt(null, $arrValid); |
|
| 84 | 84 | |
| 85 | - if ( array_key_exists ( 'init' , $argv ) ) |
|
| 85 | + if (array_key_exists('init', $argv)) |
|
| 86 | 86 | { |
| 87 | - $maker = new \Classes\MakerConfigFile( $argv , $_path ); |
|
| 87 | + $maker = new \Classes\MakerConfigFile($argv, $_path); |
|
| 88 | 88 | } else |
| 89 | 89 | { |
| 90 | - $maker = new \Classes\MakerFile( new \Classes\Config( $argv , $_path ) ); |
|
| 90 | + $maker = new \Classes\MakerFile(new \Classes\Config($argv, $_path)); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $maker->run (); |
|
| 93 | + $maker->run(); |
|
| 94 | 94 | |
| 95 | -} catch ( \Exception $e ) |
|
| 95 | +} catch (\Exception $e) |
|
| 96 | 96 | { |
| 97 | - die( $e->getMessage () ); |
|
| 97 | + die($e->getMessage()); |
|
| 98 | 98 | } |
@@ -3,15 +3,15 @@ |
||
| 3 | 3 | /** |
| 4 | 4 | * Application Entity |
| 5 | 5 | * |
| 6 | - * <?=$this->config->last_modify."\n"?> |
|
| 6 | + * <?=$this->config->last_modify . "\n"?> |
|
| 7 | 7 | * |
| 8 | 8 | * @package <?=$this->config->namespace?>Model |
| 9 | 9 | * @subpackage Model |
| 10 | - * @author <?=$this->config->author."\n"?> |
|
| 10 | + * @author <?=$this->config->author . "\n"?> |
|
| 11 | 11 | * |
| 12 | - * @copyright <?=$this->config->copyright."\n"?> |
|
| 13 | - * @license <?=$this->config->license."\n"?> |
|
| 14 | - * @link <?=$this->config->link."\n"?> |
|
| 12 | + * @copyright <?=$this->config->copyright . "\n"?> |
|
| 13 | + * @license <?=$this->config->license . "\n"?> |
|
| 14 | + * @link <?=$this->config->link . "\n"?> |
|
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | abstract class <?=$this->config->namespace?>Model_EntityAbstract extends Zend_Db_Table_Row_Abstract |
@@ -71,7 +71,6 @@ |
||
| 71 | 71 | /** |
| 72 | 72 | * Retorna um Array com nome das tabelas |
| 73 | 73 | * |
| 74 | - * @param void $schema |
|
| 75 | 74 | * |
| 76 | 75 | * @return string[] |
| 77 | 76 | */ |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | { |
| 165 | 165 | $pdo = $this->getPDO (); |
| 166 | 166 | $return1 = $pdo->query ( "SELECT pg_get_serial_sequence('$table', '$column');" ) |
| 167 | - ->fetchColumn (); |
|
| 167 | + ->fetchColumn (); |
|
| 168 | 168 | |
| 169 | 169 | if ( $return1 ) |
| 170 | 170 | { |
@@ -229,10 +229,10 @@ discard block |
||
| 229 | 229 | ); |
| 230 | 230 | |
| 231 | 231 | $this->getTable ( $key , $schema ) |
| 232 | - ->addColumn ( $column ) |
|
| 233 | - ->setNamespace ( |
|
| 234 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 235 | - ); |
|
| 232 | + ->addColumn ( $column ) |
|
| 233 | + ->setNamespace ( |
|
| 234 | + $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 235 | + ); |
|
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | 238 | |
@@ -27,43 +27,43 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @type array|\string[] |
| 29 | 29 | */ |
| 30 | - protected $schema = array ( 'public' ); |
|
| 30 | + protected $schema = array('public'); |
|
| 31 | 31 | |
| 32 | - protected $dataTypes = array ( |
|
| 32 | + protected $dataTypes = array( |
|
| 33 | 33 | /* Numeric Types */ |
| 34 | - 'smallint' => 'int' , |
|
| 35 | - 'integer' => 'int' , |
|
| 36 | - 'bigint' => 'float' , |
|
| 37 | - 'decimal' => 'float' , |
|
| 38 | - 'numeric' => 'float' , |
|
| 39 | - 'real' => 'float' , |
|
| 40 | - 'double precision' => 'float' , |
|
| 41 | - 'serial' => 'int' , |
|
| 42 | - 'bigserial' => 'float' , |
|
| 34 | + 'smallint' => 'int', |
|
| 35 | + 'integer' => 'int', |
|
| 36 | + 'bigint' => 'float', |
|
| 37 | + 'decimal' => 'float', |
|
| 38 | + 'numeric' => 'float', |
|
| 39 | + 'real' => 'float', |
|
| 40 | + 'double precision' => 'float', |
|
| 41 | + 'serial' => 'int', |
|
| 42 | + 'bigserial' => 'float', |
|
| 43 | 43 | /* Monetary Types */ |
| 44 | - 'money' => 'float' , |
|
| 44 | + 'money' => 'float', |
|
| 45 | 45 | /* Character Types */ |
| 46 | - 'character varyin' => 'string' , |
|
| 47 | - 'varchar' => 'string' , |
|
| 48 | - 'character' => 'string' , |
|
| 49 | - 'char' => 'string' , |
|
| 50 | - 'text' => 'string' , |
|
| 46 | + 'character varyin' => 'string', |
|
| 47 | + 'varchar' => 'string', |
|
| 48 | + 'character' => 'string', |
|
| 49 | + 'char' => 'string', |
|
| 50 | + 'text' => 'string', |
|
| 51 | 51 | /* Binary Data Types */ |
| 52 | - 'bytea' => 'string' , |
|
| 52 | + 'bytea' => 'string', |
|
| 53 | 53 | /* Date/Time Types */ |
| 54 | - 'datatime' => 'date' , |
|
| 55 | - 'date' => 'date' , |
|
| 54 | + 'datatime' => 'date', |
|
| 55 | + 'date' => 'date', |
|
| 56 | 56 | |
| 57 | 57 | /* Boolean Type */ |
| 58 | 58 | 'boolean' => 'boolean' |
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | - public function __construct ( AbstractAdapter $adapterConfig ) |
|
| 61 | + public function __construct(AbstractAdapter $adapterConfig) |
|
| 62 | 62 | { |
| 63 | - parent::__construct ( $adapterConfig ); |
|
| 64 | - if ( $adapterConfig->hasSchemas () ) |
|
| 63 | + parent::__construct($adapterConfig); |
|
| 64 | + if ($adapterConfig->hasSchemas()) |
|
| 65 | 65 | { |
| 66 | - $this->schema = $adapterConfig->getSchemas (); |
|
| 66 | + $this->schema = $adapterConfig->getSchemas(); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | } |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * @return string[] |
| 77 | 77 | */ |
| 78 | - public function getListNameTable () |
|
| 78 | + public function getListNameTable() |
|
| 79 | 79 | { |
| 80 | - if ( empty( $this->tableList ) ) |
|
| 80 | + if (empty($this->tableList)) |
|
| 81 | 81 | { |
| 82 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 82 | + $strSchema = implode("', '", $this->schema); |
|
| 83 | 83 | |
| 84 | - $this->tableList = $this->getPDO ()->query ( |
|
| 84 | + $this->tableList = $this->getPDO()->query( |
|
| 85 | 85 | "SELECT table_schema, |
| 86 | 86 | table_name |
| 87 | 87 | FROM information_schema.tables |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | table_schema, |
| 93 | 93 | table_name |
| 94 | 94 | ASC" |
| 95 | - )->fetchAll (); |
|
| 95 | + )->fetchAll(); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | return $this->tableList; |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return array |
| 105 | 105 | */ |
| 106 | - public function getListColumns () |
|
| 106 | + public function getListColumns() |
|
| 107 | 107 | { |
| 108 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 108 | + $strSchema = implode("', '", $this->schema); |
|
| 109 | 109 | |
| 110 | - return $this->getPDO ()->query ( |
|
| 110 | + return $this->getPDO()->query( |
|
| 111 | 111 | "SELECT distinct |
| 112 | 112 | c.table_schema, |
| 113 | 113 | c.table_name, |
@@ -121,14 +121,14 @@ discard block |
||
| 121 | 121 | ON st.table_name=c.table_name and st.table_type = 'BASE TABLE' |
| 122 | 122 | and c.table_schema IN ('$strSchema') |
| 123 | 123 | order by c.table_name asc" |
| 124 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 124 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - public function getListConstrant () |
|
| 127 | + public function getListConstrant() |
|
| 128 | 128 | { |
| 129 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 129 | + $strSchema = implode("', '", $this->schema); |
|
| 130 | 130 | |
| 131 | - return $this->getPDO ()->query ( |
|
| 131 | + return $this->getPDO()->query( |
|
| 132 | 132 | "SELECT distinct |
| 133 | 133 | tc.constraint_type, |
| 134 | 134 | tc.constraint_name, |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | ON tc.constraint_name = ccu.constraint_name |
| 149 | 149 | AND tc.constraint_schema = ccu.constraint_schema |
| 150 | 150 | ORDER by tc.table_schema" |
| 151 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 151 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | |
@@ -160,20 +160,20 @@ discard block |
||
| 160 | 160 | * |
| 161 | 161 | * @return string |
| 162 | 162 | */ |
| 163 | - public function getSequence ( $table , $column ) |
|
| 163 | + public function getSequence($table, $column) |
|
| 164 | 164 | { |
| 165 | - $pdo = $this->getPDO (); |
|
| 166 | - $return1 = $pdo->query ( "SELECT pg_get_serial_sequence('$table', '$column');" ) |
|
| 167 | - ->fetchColumn (); |
|
| 165 | + $pdo = $this->getPDO(); |
|
| 166 | + $return1 = $pdo->query("SELECT pg_get_serial_sequence('$table', '$column');") |
|
| 167 | + ->fetchColumn(); |
|
| 168 | 168 | |
| 169 | - if ( $return1 ) |
|
| 169 | + if ($return1) |
|
| 170 | 170 | { |
| 171 | 171 | return $return1; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - $dtbase = explode ( '.' , $table );; |
|
| 174 | + $dtbase = explode('.', $table); ; |
|
| 175 | 175 | |
| 176 | - $stmt = $pdo->prepare ( |
|
| 176 | + $stmt = $pdo->prepare( |
|
| 177 | 177 | "SELECT adsrc FROM pg_attrdef AS att |
| 178 | 178 | INNER JOIN pg_class AS c |
| 179 | 179 | ON adrelid = c.oid AND att.adnum=1 AND c.relname = ? |
@@ -181,19 +181,19 @@ discard block |
||
| 181 | 181 | ON n.oid = c.relnamespace and n.nspname=?" |
| 182 | 182 | ); |
| 183 | 183 | |
| 184 | - $schema = isset( $dtbase[ 1 ] ) ? $dtbase[ 1 ] : 'public'; |
|
| 184 | + $schema = isset($dtbase[1]) ? $dtbase[1] : 'public'; |
|
| 185 | 185 | |
| 186 | - $stmt->bindParam ( 1 , $schema ); |
|
| 187 | - $stmt->bindParam ( 2 , $dtbase[ 0 ] ); |
|
| 188 | - $stmt->execute (); |
|
| 189 | - $return2 = $stmt->fetchColumn (); |
|
| 190 | - if ( $return2 ) |
|
| 186 | + $stmt->bindParam(1, $schema); |
|
| 187 | + $stmt->bindParam(2, $dtbase[0]); |
|
| 188 | + $stmt->execute(); |
|
| 189 | + $return2 = $stmt->fetchColumn(); |
|
| 190 | + if ($return2) |
|
| 191 | 191 | { |
| 192 | - return preg_filter ( |
|
| 193 | - array ( |
|
| 194 | - '/nextval\(\'/' , |
|
| 192 | + return preg_filter( |
|
| 193 | + array( |
|
| 194 | + '/nextval\(\'/', |
|
| 195 | 195 | '/\'::regclass\)/' |
| 196 | - ) , '' , $return2 |
|
| 196 | + ), '', $return2 |
|
| 197 | 197 | ); |
| 198 | 198 | } |
| 199 | 199 | |
@@ -202,36 +202,36 @@ discard block |
||
| 202 | 202 | /** |
| 203 | 203 | * @inheritDoc |
| 204 | 204 | */ |
| 205 | - public function parseTables () |
|
| 205 | + public function parseTables() |
|
| 206 | 206 | { |
| 207 | - if ( $this->hasTables () ) |
|
| 207 | + if ($this->hasTables()) |
|
| 208 | 208 | { |
| 209 | - return $this->getAllTables (); |
|
| 209 | + return $this->getAllTables(); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - foreach ( $this->getListColumns () as $table ) |
|
| 212 | + foreach ($this->getListColumns() as $table) |
|
| 213 | 213 | { |
| 214 | - $schema = $table[ 'table_schema' ]; |
|
| 215 | - $key = $table [ 'table_name' ]; |
|
| 216 | - if ( ! $this->hasTable ( $key , $schema ) ) |
|
| 214 | + $schema = $table['table_schema']; |
|
| 215 | + $key = $table ['table_name']; |
|
| 216 | + if ( ! $this->hasTable($key, $schema)) |
|
| 217 | 217 | { |
| 218 | - $this->createTable ( $key , $schema ); |
|
| 218 | + $this->createTable($key, $schema); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - $column = Column::getInstance () |
|
| 222 | - ->populate ( |
|
| 223 | - array ( |
|
| 224 | - 'name' => $table [ 'column_name' ] , |
|
| 225 | - 'type' => $this->convertTypeToPhp ( $table[ 'data_type' ] ) , |
|
| 226 | - 'nullable' => ( $table[ 'is_nullable' ] == 'YES' ) , |
|
| 227 | - 'max_length' => $table[ 'max_length' ] |
|
| 221 | + $column = Column::getInstance() |
|
| 222 | + ->populate( |
|
| 223 | + array( |
|
| 224 | + 'name' => $table ['column_name'], |
|
| 225 | + 'type' => $this->convertTypeToPhp($table['data_type']), |
|
| 226 | + 'nullable' => ($table['is_nullable'] == 'YES'), |
|
| 227 | + 'max_length' => $table['max_length'] |
|
| 228 | 228 | ) |
| 229 | 229 | ); |
| 230 | 230 | |
| 231 | - $this->getTable ( $key , $schema ) |
|
| 232 | - ->addColumn ( $column ) |
|
| 233 | - ->setNamespace ( |
|
| 234 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 231 | + $this->getTable($key, $schema) |
|
| 232 | + ->addColumn($column) |
|
| 233 | + ->setNamespace( |
|
| 234 | + $this->config->createClassNamespace($this->getTable($key, $schema)) |
|
| 235 | 235 | ); |
| 236 | 236 | } |
| 237 | 237 | } |
@@ -240,12 +240,12 @@ discard block |
||
| 240 | 240 | * @inheritDoc |
| 241 | 241 | * @return string |
| 242 | 242 | */ |
| 243 | - public function getPDOString () |
|
| 243 | + public function getPDOString() |
|
| 244 | 244 | { |
| 245 | - return sprintf ( |
|
| 246 | - "pgsql:host=%s;port=%s;dbname=%s" , |
|
| 247 | - $this->host , |
|
| 248 | - $this->port , |
|
| 245 | + return sprintf( |
|
| 246 | + "pgsql:host=%s;port=%s;dbname=%s", |
|
| 247 | + $this->host, |
|
| 248 | + $this->port, |
|
| 249 | 249 | $this->database |
| 250 | 250 | |
| 251 | 251 | ); |
@@ -255,11 +255,11 @@ discard block |
||
| 255 | 255 | * @inheritDoc |
| 256 | 256 | * @return string |
| 257 | 257 | */ |
| 258 | - public function getPDOSocketString () |
|
| 258 | + public function getPDOSocketString() |
|
| 259 | 259 | { |
| 260 | - return sprintf ( |
|
| 261 | - "pgsql:unix_socket=%s;dbname=%s" , |
|
| 262 | - $this->socket , |
|
| 260 | + return sprintf( |
|
| 261 | + "pgsql:unix_socket=%s;dbname=%s", |
|
| 262 | + $this->socket, |
|
| 263 | 263 | $this->database |
| 264 | 264 | |
| 265 | 265 | ); |
@@ -270,19 +270,19 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return int |
| 272 | 272 | */ |
| 273 | - public function getTotalTables () |
|
| 273 | + public function getTotalTables() |
|
| 274 | 274 | { |
| 275 | - if ( empty( $this->totalTables ) ) |
|
| 275 | + if (empty($this->totalTables)) |
|
| 276 | 276 | { |
| 277 | - $strSchema = implode ( "', '" , $this->schema ); |
|
| 277 | + $strSchema = implode("', '", $this->schema); |
|
| 278 | 278 | |
| 279 | - $this->totalTables = $this->getPDO ()->query ( |
|
| 279 | + $this->totalTables = $this->getPDO()->query( |
|
| 280 | 280 | "SELECT COUNT(table_name) AS total |
| 281 | 281 | FROM information_schema.tables |
| 282 | 282 | WHERE |
| 283 | 283 | table_type = 'BASE TABLE' |
| 284 | 284 | AND table_schema IN ( '" . $strSchema . "' )" |
| 285 | - )->fetchColumn (); |
|
| 285 | + )->fetchColumn(); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | return (int) $this->totalTables; |
@@ -106,30 +106,30 @@ discard block |
||
| 106 | 106 | if ( $table->hasColumn ( $constrant[ "column_name" ] ) ) |
| 107 | 107 | { |
| 108 | 108 | $objConstrant = Constrant::getInstance () |
| 109 | - ->populate ( |
|
| 110 | - array ( |
|
| 111 | - 'constrant' => $constrant[ 'constraint_name' ] , |
|
| 112 | - 'schema' => $constrant[ 'foreign_schema' ] , |
|
| 113 | - 'table' => $constrant[ 'foreign_table' ] , |
|
| 114 | - 'column' => $constrant[ 'foreign_column' ] |
|
| 115 | - ) |
|
| 116 | - ); |
|
| 109 | + ->populate ( |
|
| 110 | + array ( |
|
| 111 | + 'constrant' => $constrant[ 'constraint_name' ] , |
|
| 112 | + 'schema' => $constrant[ 'foreign_schema' ] , |
|
| 113 | + 'table' => $constrant[ 'foreign_table' ] , |
|
| 114 | + 'column' => $constrant[ 'foreign_column' ] |
|
| 115 | + ) |
|
| 116 | + ); |
|
| 117 | 117 | |
| 118 | 118 | switch ( $constrant[ 'constraint_type' ] ) |
| 119 | 119 | { |
| 120 | 120 | case "FOREIGN KEY": |
| 121 | 121 | $table->getColumn ( $constrant[ "column_name" ] ) |
| 122 | - ->addRefFk ( $objConstrant ); |
|
| 122 | + ->addRefFk ( $objConstrant ); |
|
| 123 | 123 | break; |
| 124 | 124 | case"PRIMARY KEY": |
| 125 | 125 | $table->getColumn ( $constrant[ "column_name" ] ) |
| 126 | - ->setPrimaryKey ( $objConstrant ) |
|
| 127 | - ->setSequence ( |
|
| 128 | - $this->getSequence ( |
|
| 129 | - $schema . '.' . $table_name , |
|
| 130 | - $constrant[ "column_name" ] |
|
| 131 | - ) |
|
| 132 | - ); |
|
| 126 | + ->setPrimaryKey ( $objConstrant ) |
|
| 127 | + ->setSequence ( |
|
| 128 | + $this->getSequence ( |
|
| 129 | + $schema . '.' . $table_name , |
|
| 130 | + $constrant[ "column_name" ] |
|
| 131 | + ) |
|
| 132 | + ); |
|
| 133 | 133 | break; |
| 134 | 134 | } |
| 135 | 135 | } |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | if ( $table->hasColumn ( $constrant[ "foreign_column" ] ) ) |
| 150 | 150 | { |
| 151 | 151 | $table->getColumn ( $constrant[ "foreign_column" ] ) |
| 152 | - ->createDependece ( |
|
| 153 | - $constrant[ 'constraint_name' ] , |
|
| 154 | - $constrant[ 'table_name' ] , |
|
| 155 | - $constrant[ 'column_name' ] , |
|
| 156 | - $constrant[ 'table_schema' ] |
|
| 157 | - ); |
|
| 152 | + ->createDependece ( |
|
| 153 | + $constrant[ 'constraint_name' ] , |
|
| 154 | + $constrant[ 'table_name' ] , |
|
| 155 | + $constrant[ 'column_name' ] , |
|
| 156 | + $constrant[ 'table_schema' ] |
|
| 157 | + ); |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | public function createTable ( $nameTable , $schema = 0 ) |
| 221 | 221 | { |
| 222 | 222 | $this->objDbTables[ $schema ][ trim ( $nameTable ) ] = DbTable::getInstance () |
| 223 | - ->populate ( |
|
| 224 | - array ( |
|
| 225 | - 'table' => $nameTable , |
|
| 226 | - 'schema' => $schema , |
|
| 227 | - 'database' => $this->database |
|
| 228 | - ) |
|
| 229 | - ); |
|
| 223 | + ->populate ( |
|
| 224 | + array ( |
|
| 225 | + 'table' => $nameTable , |
|
| 226 | + 'schema' => $schema , |
|
| 227 | + 'database' => $this->database |
|
| 228 | + ) |
|
| 229 | + ); |
|
| 230 | 230 | |
| 231 | 231 | return $this; |
| 232 | 232 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | /** |
| 59 | 59 | * @type \Classes\Db\DbTable[][] |
| 60 | 60 | */ |
| 61 | - private $objDbTables = array (); |
|
| 61 | + private $objDbTables = array(); |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * @var AbstractAdapter |
@@ -73,22 +73,22 @@ discard block |
||
| 73 | 73 | /** |
| 74 | 74 | * analisa e popula as Foreing keys, Primary keys e dependencias do banco nos objetos |
| 75 | 75 | */ |
| 76 | - protected function parseConstrants () |
|
| 76 | + protected function parseConstrants() |
|
| 77 | 77 | { |
| 78 | - foreach ( $this->getListConstrant () as $constrant ) |
|
| 78 | + foreach ($this->getListConstrant() as $constrant) |
|
| 79 | 79 | { |
| 80 | 80 | |
| 81 | - $schema = $constrant[ 'table_schema' ]; |
|
| 82 | - $table_name = $constrant [ 'table_name' ]; |
|
| 83 | - $this->populateForeignAndPrimaryKeys ( $constrant , $table_name , $schema ); |
|
| 84 | - unset( $table_name , $schema ); |
|
| 81 | + $schema = $constrant['table_schema']; |
|
| 82 | + $table_name = $constrant ['table_name']; |
|
| 83 | + $this->populateForeignAndPrimaryKeys($constrant, $table_name, $schema); |
|
| 84 | + unset($table_name, $schema); |
|
| 85 | 85 | |
| 86 | - if ( $constrant[ 'constraint_type' ] == "FOREIGN KEY" ) |
|
| 86 | + if ($constrant['constraint_type'] == "FOREIGN KEY") |
|
| 87 | 87 | { |
| 88 | - $schema = $constrant[ 'foreign_schema' ]; |
|
| 89 | - $table_name = $constrant [ 'foreign_table' ]; |
|
| 90 | - $this->populateDependece ( $constrant , $table_name , $schema ); |
|
| 91 | - unset( $table_name , $schema ); |
|
| 88 | + $schema = $constrant['foreign_schema']; |
|
| 89 | + $table_name = $constrant ['foreign_table']; |
|
| 90 | + $this->populateDependece($constrant, $table_name, $schema); |
|
| 91 | + unset($table_name, $schema); |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -98,36 +98,36 @@ discard block |
||
| 98 | 98 | * @param string $table_name |
| 99 | 99 | * @param int $schema |
| 100 | 100 | */ |
| 101 | - private function populateForeignAndPrimaryKeys ( $constrant , $table_name , $schema = 0 ) |
|
| 101 | + private function populateForeignAndPrimaryKeys($constrant, $table_name, $schema = 0) |
|
| 102 | 102 | { |
| 103 | - if ( $this->hasTable ( $table_name , $schema ) ) |
|
| 103 | + if ($this->hasTable($table_name, $schema)) |
|
| 104 | 104 | { |
| 105 | - $table = $this->getTable ( $table_name , $schema ); |
|
| 106 | - if ( $table->hasColumn ( $constrant[ "column_name" ] ) ) |
|
| 105 | + $table = $this->getTable($table_name, $schema); |
|
| 106 | + if ($table->hasColumn($constrant["column_name"])) |
|
| 107 | 107 | { |
| 108 | - $objConstrant = Constrant::getInstance () |
|
| 109 | - ->populate ( |
|
| 110 | - array ( |
|
| 111 | - 'constrant' => $constrant[ 'constraint_name' ] , |
|
| 112 | - 'schema' => $constrant[ 'foreign_schema' ] , |
|
| 113 | - 'table' => $constrant[ 'foreign_table' ] , |
|
| 114 | - 'column' => $constrant[ 'foreign_column' ] |
|
| 108 | + $objConstrant = Constrant::getInstance() |
|
| 109 | + ->populate( |
|
| 110 | + array( |
|
| 111 | + 'constrant' => $constrant['constraint_name'], |
|
| 112 | + 'schema' => $constrant['foreign_schema'], |
|
| 113 | + 'table' => $constrant['foreign_table'], |
|
| 114 | + 'column' => $constrant['foreign_column'] |
|
| 115 | 115 | ) |
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | - switch ( $constrant[ 'constraint_type' ] ) |
|
| 118 | + switch ($constrant['constraint_type']) |
|
| 119 | 119 | { |
| 120 | 120 | case "FOREIGN KEY": |
| 121 | - $table->getColumn ( $constrant[ "column_name" ] ) |
|
| 122 | - ->addRefFk ( $objConstrant ); |
|
| 121 | + $table->getColumn($constrant["column_name"]) |
|
| 122 | + ->addRefFk($objConstrant); |
|
| 123 | 123 | break; |
| 124 | 124 | case"PRIMARY KEY": |
| 125 | - $table->getColumn ( $constrant[ "column_name" ] ) |
|
| 126 | - ->setPrimaryKey ( $objConstrant ) |
|
| 127 | - ->setSequence ( |
|
| 128 | - $this->getSequence ( |
|
| 129 | - $schema . '.' . $table_name , |
|
| 130 | - $constrant[ "column_name" ] |
|
| 125 | + $table->getColumn($constrant["column_name"]) |
|
| 126 | + ->setPrimaryKey($objConstrant) |
|
| 127 | + ->setSequence( |
|
| 128 | + $this->getSequence( |
|
| 129 | + $schema . '.' . $table_name, |
|
| 130 | + $constrant["column_name"] |
|
| 131 | 131 | ) |
| 132 | 132 | ); |
| 133 | 133 | break; |
@@ -141,19 +141,19 @@ discard block |
||
| 141 | 141 | * @param string $table_name |
| 142 | 142 | * @param int $schema |
| 143 | 143 | */ |
| 144 | - private function populateDependece ( $constrant , $table_name , $schema = 0 ) |
|
| 144 | + private function populateDependece($constrant, $table_name, $schema = 0) |
|
| 145 | 145 | { |
| 146 | - if ( $this->hasTable ( $table_name , $schema ) ) |
|
| 146 | + if ($this->hasTable($table_name, $schema)) |
|
| 147 | 147 | { |
| 148 | - $table = $this->getTable ( $table_name , $schema ); |
|
| 149 | - if ( $table->hasColumn ( $constrant[ "foreign_column" ] ) ) |
|
| 148 | + $table = $this->getTable($table_name, $schema); |
|
| 149 | + if ($table->hasColumn($constrant["foreign_column"])) |
|
| 150 | 150 | { |
| 151 | - $table->getColumn ( $constrant[ "foreign_column" ] ) |
|
| 152 | - ->createDependece ( |
|
| 153 | - $constrant[ 'constraint_name' ] , |
|
| 154 | - $constrant[ 'table_name' ] , |
|
| 155 | - $constrant[ 'column_name' ] , |
|
| 156 | - $constrant[ 'table_schema' ] |
|
| 151 | + $table->getColumn($constrant["foreign_column"]) |
|
| 152 | + ->createDependece( |
|
| 153 | + $constrant['constraint_name'], |
|
| 154 | + $constrant['table_name'], |
|
| 155 | + $constrant['column_name'], |
|
| 156 | + $constrant['table_schema'] |
|
| 157 | 157 | ); |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -162,14 +162,14 @@ discard block |
||
| 162 | 162 | /** |
| 163 | 163 | * cria um Array com nome das tabelas |
| 164 | 164 | */ |
| 165 | - abstract protected function parseTables (); |
|
| 165 | + abstract protected function parseTables(); |
|
| 166 | 166 | |
| 167 | 167 | /** |
| 168 | 168 | * retorna o numero total de tabelas |
| 169 | 169 | * |
| 170 | 170 | * @return int |
| 171 | 171 | */ |
| 172 | - abstract public function getTotalTables (); |
|
| 172 | + abstract public function getTotalTables(); |
|
| 173 | 173 | |
| 174 | 174 | /** |
| 175 | 175 | * Retorna o Nome da Sequence da tabela |
@@ -179,23 +179,23 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @return string |
| 181 | 181 | */ |
| 182 | - abstract public function getSequence ( $table , $column ); |
|
| 182 | + abstract public function getSequence($table, $column); |
|
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | 185 | * @return array |
| 186 | 186 | */ |
| 187 | - abstract public function getListConstrant (); |
|
| 187 | + abstract public function getListConstrant(); |
|
| 188 | 188 | |
| 189 | 189 | /** |
| 190 | 190 | * @param string $str |
| 191 | 191 | * |
| 192 | 192 | * @return string |
| 193 | 193 | */ |
| 194 | - protected function convertTypeToPhp ( $str ) |
|
| 194 | + protected function convertTypeToPhp($str) |
|
| 195 | 195 | { |
| 196 | - if ( isset( $this->dataTypes[ $str ] ) ) |
|
| 196 | + if (isset($this->dataTypes[$str])) |
|
| 197 | 197 | { |
| 198 | - return $this->dataTypes[ $str ]; |
|
| 198 | + return $this->dataTypes[$str]; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | return 'string'; |
@@ -204,12 +204,12 @@ discard block |
||
| 204 | 204 | /** |
| 205 | 205 | * @return string |
| 206 | 206 | */ |
| 207 | - abstract public function getPDOString (); |
|
| 207 | + abstract public function getPDOString(); |
|
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | - abstract public function getPDOSocketString (); |
|
| 212 | + abstract public function getPDOSocketString(); |
|
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | 215 | * @param $nameTable |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return \Classes\Db\DbTable |
| 219 | 219 | */ |
| 220 | - public function createTable ( $nameTable , $schema = 0 ) |
|
| 220 | + public function createTable($nameTable, $schema = 0) |
|
| 221 | 221 | { |
| 222 | - $this->objDbTables[ $schema ][ trim ( $nameTable ) ] = DbTable::getInstance () |
|
| 223 | - ->populate ( |
|
| 224 | - array ( |
|
| 225 | - 'table' => $nameTable , |
|
| 226 | - 'schema' => $schema , |
|
| 222 | + $this->objDbTables[$schema][trim($nameTable)] = DbTable::getInstance() |
|
| 223 | + ->populate( |
|
| 224 | + array( |
|
| 225 | + 'table' => $nameTable, |
|
| 226 | + 'schema' => $schema, |
|
| 227 | 227 | 'database' => $this->database |
| 228 | 228 | ) |
| 229 | 229 | ); |
@@ -236,24 +236,24 @@ discard block |
||
| 236 | 236 | * |
| 237 | 237 | * @return \Classes\Db\DbTable[] |
| 238 | 238 | */ |
| 239 | - public function getTables ( $schema = 0 ) |
|
| 239 | + public function getTables($schema = 0) |
|
| 240 | 240 | { |
| 241 | - if ( ! isset( $this->objDbTables[ $schema ] ) ) |
|
| 241 | + if ( ! isset($this->objDbTables[$schema])) |
|
| 242 | 242 | { |
| 243 | - return array (); |
|
| 243 | + return array(); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - return $this->objDbTables[ $schema ]; |
|
| 246 | + return $this->objDbTables[$schema]; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - public function getAllTables () |
|
| 249 | + public function getAllTables() |
|
| 250 | 250 | { |
| 251 | 251 | return $this->objDbTables; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - public function hasTables () |
|
| 254 | + public function hasTables() |
|
| 255 | 255 | { |
| 256 | - return ! empty( $this->objDbTables ); |
|
| 256 | + return ! empty($this->objDbTables); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -263,9 +263,9 @@ discard block |
||
| 263 | 263 | * |
| 264 | 264 | * @return \Classes\Db\DbTable |
| 265 | 265 | */ |
| 266 | - public function getTable ( $nameTable , $schema = 0 ) |
|
| 266 | + public function getTable($nameTable, $schema = 0) |
|
| 267 | 267 | { |
| 268 | - return $this->objDbTables[ $schema ][ trim ( $nameTable ) ]; |
|
| 268 | + return $this->objDbTables[$schema][trim($nameTable)]; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -274,9 +274,9 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @return bool |
| 276 | 276 | */ |
| 277 | - public function hasTable ( $nameTable , $schema = 0 ) |
|
| 277 | + public function hasTable($nameTable, $schema = 0) |
|
| 278 | 278 | { |
| 279 | - return isset( $this->objDbTables[ $schema ][ trim ( $nameTable ) ] ); |
|
| 279 | + return isset($this->objDbTables[$schema][trim($nameTable)]); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -284,64 +284,64 @@ discard block |
||
| 284 | 284 | * |
| 285 | 285 | * @return array[] |
| 286 | 286 | */ |
| 287 | - abstract public function getListColumns (); |
|
| 287 | + abstract public function getListColumns(); |
|
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | 290 | * Retorna um Array com nome das tabelas |
| 291 | 291 | * |
| 292 | 292 | * @return string[] |
| 293 | 293 | */ |
| 294 | - abstract public function getListNameTable (); |
|
| 294 | + abstract public function getListNameTable(); |
|
| 295 | 295 | |
| 296 | 296 | /** |
| 297 | 297 | * @param \Classes\AdapterConfig\AbstractAdapter $adapterConfig |
| 298 | 298 | */ |
| 299 | - public function __construct ( AbstractAdapter $adapterConfig ) |
|
| 299 | + public function __construct(AbstractAdapter $adapterConfig) |
|
| 300 | 300 | { |
| 301 | 301 | $this->config = $adapterConfig; |
| 302 | - $this->host = $adapterConfig->getHost (); |
|
| 303 | - $this->database = $adapterConfig->getDatabase (); |
|
| 304 | - $this->port = $adapterConfig->hasPort () ? $adapterConfig->getPort () |
|
| 302 | + $this->host = $adapterConfig->getHost(); |
|
| 303 | + $this->database = $adapterConfig->getDatabase(); |
|
| 304 | + $this->port = $adapterConfig->hasPort() ? $adapterConfig->getPort() |
|
| 305 | 305 | : $this->port; |
| 306 | - $this->username = $adapterConfig->getUser (); |
|
| 307 | - $this->password = $adapterConfig->getPassword (); |
|
| 308 | - $this->socket = $adapterConfig->getSocket (); |
|
| 306 | + $this->username = $adapterConfig->getUser(); |
|
| 307 | + $this->password = $adapterConfig->getPassword(); |
|
| 308 | + $this->socket = $adapterConfig->getSocket(); |
|
| 309 | 309 | |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
| 313 | 313 | * Executa as consultas do banco de dados |
| 314 | 314 | */ |
| 315 | - public function runDatabase () |
|
| 315 | + public function runDatabase() |
|
| 316 | 316 | { |
| 317 | - $this->parseTables (); |
|
| 318 | - $this->parseConstrants (); |
|
| 317 | + $this->parseTables(); |
|
| 318 | + $this->parseConstrants(); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
| 322 | 322 | * |
| 323 | 323 | * @return \PDO |
| 324 | 324 | */ |
| 325 | - public function getPDO () |
|
| 325 | + public function getPDO() |
|
| 326 | 326 | { |
| 327 | - if ( is_null ( $this->_pdo ) ) |
|
| 327 | + if (is_null($this->_pdo)) |
|
| 328 | 328 | { |
| 329 | - if ( ! empty( $this->socket ) ) |
|
| 329 | + if ( ! empty($this->socket)) |
|
| 330 | 330 | { |
| 331 | - $pdoString = $this->getPDOSocketString (); |
|
| 331 | + $pdoString = $this->getPDOSocketString(); |
|
| 332 | 332 | } else |
| 333 | 333 | { |
| 334 | - $pdoString = $this->getPDOString (); |
|
| 334 | + $pdoString = $this->getPDOString(); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | try |
| 338 | 338 | { |
| 339 | - $this->_pdo = new \PDO ( |
|
| 340 | - $pdoString , $this->username , $this->password |
|
| 339 | + $this->_pdo = new \PDO( |
|
| 340 | + $pdoString, $this->username, $this->password |
|
| 341 | 341 | ); |
| 342 | - } catch ( \Exception $e ) |
|
| 342 | + } catch (\Exception $e) |
|
| 343 | 343 | { |
| 344 | - die ( "pdo error: " . $e->getMessage () . "\n" ); |
|
| 344 | + die ("pdo error: " . $e->getMessage() . "\n"); |
|
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | 347 | |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | 84 | $this->getTable ( $key , $schema ) |
| 85 | - ->addColumn ( $column ) |
|
| 86 | - ->setNamespace ( |
|
| 87 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 88 | - ); |
|
| 85 | + ->addColumn ( $column ) |
|
| 86 | + ->setNamespace ( |
|
| 87 | + $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 88 | + ); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | public function getSequence ( $table , $column ) |
| 209 | 209 | { |
| 210 | 210 | $return = $this->getPDO () |
| 211 | - ->query ( "select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';" ) |
|
| 212 | - ->fetch ( \PDO::FETCH_ASSOC ); |
|
| 211 | + ->query ( "select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';" ) |
|
| 212 | + ->fetch ( \PDO::FETCH_ASSOC ); |
|
| 213 | 213 | |
| 214 | 214 | if ( ! $return ) |
| 215 | 215 | { |
@@ -30,20 +30,20 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - protected function convertTypeToPhp ( $str ) |
|
| 33 | + protected function convertTypeToPhp($str) |
|
| 34 | 34 | { |
| 35 | - if ( preg_match ( '/(tinyint\(1\)|bit)/' , $str ) ) |
|
| 35 | + if (preg_match('/(tinyint\(1\)|bit)/', $str)) |
|
| 36 | 36 | { |
| 37 | 37 | $res = 'boolean'; |
| 38 | - } elseif ( preg_match ( '/(datetime|timestamp|blob|char|enum|text|date)/' , $str ) ) |
|
| 38 | + } elseif (preg_match('/(datetime|timestamp|blob|char|enum|text|date)/', $str)) |
|
| 39 | 39 | { |
| 40 | 40 | $res = 'string'; |
| 41 | - } elseif ( preg_match ( '/(decimal|numeric|float|double)/' , $str ) ) |
|
| 41 | + } elseif (preg_match('/(decimal|numeric|float|double)/', $str)) |
|
| 42 | 42 | { |
| 43 | 43 | $res = 'float'; |
| 44 | - } elseif ( preg_match ( '#^(?:tiny|small|medium|long|big|var)?(\w+)(?:\(\d+\))?(?:\s\w+)*$#' , $str , $matches ) ) |
|
| 44 | + } elseif (preg_match('#^(?:tiny|small|medium|long|big|var)?(\w+)(?:\(\d+\))?(?:\s\w+)*$#', $str, $matches)) |
|
| 45 | 45 | { |
| 46 | - $res = $matches[ 1 ]; |
|
| 46 | + $res = $matches[1]; |
|
| 47 | 47 | } else |
| 48 | 48 | { |
| 49 | 49 | print "Can't convert column type to PHP - Unrecognized type: $str"; |
@@ -55,36 +55,36 @@ discard block |
||
| 55 | 55 | /** |
| 56 | 56 | * @inheritDoc |
| 57 | 57 | */ |
| 58 | - public function parseTables () |
|
| 58 | + public function parseTables() |
|
| 59 | 59 | { |
| 60 | - if ( $this->hasTables () ) |
|
| 60 | + if ($this->hasTables()) |
|
| 61 | 61 | { |
| 62 | - return $this->getAllTables (); |
|
| 62 | + return $this->getAllTables(); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $schema = 0; |
| 66 | - foreach ( $this->getListColumns () as $table ) |
|
| 66 | + foreach ($this->getListColumns() as $table) |
|
| 67 | 67 | { |
| 68 | - $key = $table [ 'table_name' ]; |
|
| 69 | - if ( ! $this->hasTable ( $key , $schema ) ) |
|
| 68 | + $key = $table ['table_name']; |
|
| 69 | + if ( ! $this->hasTable($key, $schema)) |
|
| 70 | 70 | { |
| 71 | - $this->createTable ( $key , $schema ); |
|
| 71 | + $this->createTable($key, $schema); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $column = Column::getInstance () |
|
| 75 | - ->populate ( |
|
| 76 | - array ( |
|
| 77 | - 'name' => $table [ 'column_name' ] , |
|
| 78 | - 'type' => $this->convertTypeToPhp ( $table[ 'data_type' ] ) , |
|
| 79 | - 'nullable' => ( $table[ 'is_nullable' ] == 'YES' ) , |
|
| 80 | - 'max_length' => $table[ 'max_length' ] |
|
| 74 | + $column = Column::getInstance() |
|
| 75 | + ->populate( |
|
| 76 | + array( |
|
| 77 | + 'name' => $table ['column_name'], |
|
| 78 | + 'type' => $this->convertTypeToPhp($table['data_type']), |
|
| 79 | + 'nullable' => ($table['is_nullable'] == 'YES'), |
|
| 80 | + 'max_length' => $table['max_length'] |
|
| 81 | 81 | ) |
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | - $this->getTable ( $key , $schema ) |
|
| 85 | - ->addColumn ( $column ) |
|
| 86 | - ->setNamespace ( |
|
| 87 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 84 | + $this->getTable($key, $schema) |
|
| 85 | + ->addColumn($column) |
|
| 86 | + ->setNamespace( |
|
| 87 | + $this->config->createClassNamespace($this->getTable($key, $schema)) |
|
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -93,12 +93,12 @@ discard block |
||
| 93 | 93 | * @inheritDoc |
| 94 | 94 | * @return string |
| 95 | 95 | */ |
| 96 | - public function getPDOString () |
|
| 96 | + public function getPDOString() |
|
| 97 | 97 | { |
| 98 | - return sprintf ( |
|
| 99 | - "mysql:host=%s;port=%s;dbname=%s" , |
|
| 100 | - $this->host , |
|
| 101 | - $this->port , |
|
| 98 | + return sprintf( |
|
| 99 | + "mysql:host=%s;port=%s;dbname=%s", |
|
| 100 | + $this->host, |
|
| 101 | + $this->port, |
|
| 102 | 102 | $this->database |
| 103 | 103 | |
| 104 | 104 | ); |
@@ -108,11 +108,11 @@ discard block |
||
| 108 | 108 | * @inheritDoc |
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | - public function getPDOSocketString () |
|
| 111 | + public function getPDOSocketString() |
|
| 112 | 112 | { |
| 113 | - return sprintf ( |
|
| 114 | - "mysql:unix_socket=%s;dbname=%s" , |
|
| 115 | - $this->socket , |
|
| 113 | + return sprintf( |
|
| 114 | + "mysql:unix_socket=%s;dbname=%s", |
|
| 115 | + $this->socket, |
|
| 116 | 116 | $this->database |
| 117 | 117 | |
| 118 | 118 | ); |
@@ -122,13 +122,13 @@ discard block |
||
| 122 | 122 | * @inheritDoc |
| 123 | 123 | * @return string[] |
| 124 | 124 | */ |
| 125 | - public function getListNameTable () |
|
| 125 | + public function getListNameTable() |
|
| 126 | 126 | { |
| 127 | - if ( empty( $this->tableList ) ) |
|
| 127 | + if (empty($this->tableList)) |
|
| 128 | 128 | { |
| 129 | - $this->tableList = $this->getPDO ()->query ( |
|
| 129 | + $this->tableList = $this->getPDO()->query( |
|
| 130 | 130 | "show tables" |
| 131 | - )->fetchAll (); |
|
| 131 | + )->fetchAll(); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | return $this->tableList; |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return array[] |
| 141 | 141 | */ |
| 142 | - public function getListColumns () |
|
| 142 | + public function getListColumns() |
|
| 143 | 143 | { |
| 144 | 144 | |
| 145 | - return $this->getPDO ()->query ( |
|
| 145 | + return $this->getPDO()->query( |
|
| 146 | 146 | "select |
| 147 | 147 | 0 AS table_schema, |
| 148 | 148 | table_name, |
@@ -153,15 +153,15 @@ discard block |
||
| 153 | 153 | from information_schema.columns |
| 154 | 154 | where table_schema IN ('{$this->database}') |
| 155 | 155 | order by table_name,ordinal_position" |
| 156 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 156 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
| 160 | 160 | * @return array |
| 161 | 161 | */ |
| 162 | - public function getListConstrant () |
|
| 162 | + public function getListConstrant() |
|
| 163 | 163 | { |
| 164 | - return $this->getPDO ()->query ( |
|
| 164 | + return $this->getPDO()->query( |
|
| 165 | 165 | "SELECT distinct |
| 166 | 166 | i.constraint_type, |
| 167 | 167 | k.constraint_name, |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | WHERE |
| 179 | 179 | i.TABLE_SCHEMA IN ('{$this->database}') AND i.CONSTRAINT_TYPE IN ('FOREIGN KEY', 'PRIMARY KEY' ) |
| 180 | 180 | order by k.table_schema, k.table_name;" |
| 181 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 181 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -186,14 +186,14 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | * @return int |
| 188 | 188 | */ |
| 189 | - public function getTotalTables () |
|
| 189 | + public function getTotalTables() |
|
| 190 | 190 | { |
| 191 | - if ( empty( $this->totalTables ) ) |
|
| 191 | + if (empty($this->totalTables)) |
|
| 192 | 192 | { |
| 193 | 193 | |
| 194 | - $this->totalTables = $this->getPDO ()->query ( |
|
| 194 | + $this->totalTables = $this->getPDO()->query( |
|
| 195 | 195 | "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '{$this->database}'" |
| 196 | - )->fetchColumn (); |
|
| 196 | + )->fetchColumn(); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | return (int) $this->totalTables; |
@@ -205,13 +205,13 @@ discard block |
||
| 205 | 205 | * @param $table |
| 206 | 206 | * @param $column |
| 207 | 207 | */ |
| 208 | - public function getSequence ( $table , $column ) |
|
| 208 | + public function getSequence($table, $column) |
|
| 209 | 209 | { |
| 210 | - $return = $this->getPDO () |
|
| 211 | - ->query ( "select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';" ) |
|
| 212 | - ->fetch ( \PDO::FETCH_ASSOC ); |
|
| 210 | + $return = $this->getPDO() |
|
| 211 | + ->query("select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';") |
|
| 212 | + ->fetch(\PDO::FETCH_ASSOC); |
|
| 213 | 213 | |
| 214 | - if ( ! $return ) |
|
| 214 | + if ( ! $return) |
|
| 215 | 215 | { |
| 216 | 216 | return; |
| 217 | 217 | } |
@@ -178,14 +178,14 @@ |
||
| 178 | 178 | public function createDependece ( $constraint_name , $table_name , $column_name , $schema = null ) |
| 179 | 179 | { |
| 180 | 180 | $objConstrantDependence = Constrant::getInstance () |
| 181 | - ->populate ( |
|
| 182 | - array ( |
|
| 183 | - 'constrant' => $constraint_name , |
|
| 184 | - 'schema' => $schema , |
|
| 185 | - 'table' => $table_name , |
|
| 186 | - 'column' => $column_name |
|
| 187 | - ) |
|
| 188 | - ); |
|
| 181 | + ->populate ( |
|
| 182 | + array ( |
|
| 183 | + 'constrant' => $constraint_name , |
|
| 184 | + 'schema' => $schema , |
|
| 185 | + 'table' => $table_name , |
|
| 186 | + 'column' => $column_name |
|
| 187 | + ) |
|
| 188 | + ); |
|
| 189 | 189 | |
| 190 | 190 | $this->addDependece ( $objConstrantDependence ); |
| 191 | 191 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @author Pedro Alarcao <[email protected]> |
| 18 | 18 | */ |
| 19 | - final private function __construct () |
|
| 19 | + final private function __construct() |
|
| 20 | 20 | { |
| 21 | 21 | } |
| 22 | 22 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @return \Classes\Db\Column |
| 27 | 27 | */ |
| 28 | - public static function getInstance () |
|
| 28 | + public static function getInstance() |
|
| 29 | 29 | { |
| 30 | 30 | return new Column(); |
| 31 | 31 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | /** |
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | - public function getName () |
|
| 81 | + public function getName() |
|
| 82 | 82 | { |
| 83 | 83 | return $this->name; |
| 84 | 84 | } |
@@ -88,12 +88,12 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @param $array |
| 90 | 90 | */ |
| 91 | - public function populate ( $array ) |
|
| 91 | + public function populate($array) |
|
| 92 | 92 | { |
| 93 | - $this->name = $array[ 'name' ]; |
|
| 94 | - $this->type = $array[ 'type' ]; |
|
| 95 | - $this->nullable = $array[ 'nullable' ]; |
|
| 96 | - $this->max_length = $array[ 'max_length' ]; |
|
| 93 | + $this->name = $array['name']; |
|
| 94 | + $this->type = $array['type']; |
|
| 95 | + $this->nullable = $array['nullable']; |
|
| 96 | + $this->max_length = $array['max_length']; |
|
| 97 | 97 | |
| 98 | 98 | return $this; |
| 99 | 99 | } |
@@ -101,31 +101,31 @@ discard block |
||
| 101 | 101 | /** |
| 102 | 102 | * @return boolean |
| 103 | 103 | */ |
| 104 | - public function isPrimaryKey () |
|
| 104 | + public function isPrimaryKey() |
|
| 105 | 105 | { |
| 106 | - return ! empty( $this->primarykey ); |
|
| 106 | + return ! empty($this->primarykey); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | 110 | * @return boolean |
| 111 | 111 | */ |
| 112 | - public function isForeingkey () |
|
| 112 | + public function isForeingkey() |
|
| 113 | 113 | { |
| 114 | - return ! empty( $this->refForeingkey ); |
|
| 114 | + return ! empty($this->refForeingkey); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
| 118 | 118 | * @return boolean |
| 119 | 119 | */ |
| 120 | - public function hasDependence () |
|
| 120 | + public function hasDependence() |
|
| 121 | 121 | { |
| 122 | - return ! empty( $this->dependences ); |
|
| 122 | + return ! empty($this->dependences); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | - public function getType () |
|
| 128 | + public function getType() |
|
| 129 | 129 | { |
| 130 | 130 | return $this->type; |
| 131 | 131 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | /** |
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | - public function getComment () |
|
| 136 | + public function getComment() |
|
| 137 | 137 | { |
| 138 | 138 | return $this->comment; |
| 139 | 139 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | /** |
| 142 | 142 | * @param string $comment |
| 143 | 143 | */ |
| 144 | - public function setComment ( $comment ) |
|
| 144 | + public function setComment($comment) |
|
| 145 | 145 | { |
| 146 | 146 | $this->comment = $comment; |
| 147 | 147 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | /** |
| 152 | 152 | * @param \Classes\Db\Constrant $primarykey |
| 153 | 153 | */ |
| 154 | - public function setPrimaryKey ( Constrant $primarykey ) |
|
| 154 | + public function setPrimaryKey(Constrant $primarykey) |
|
| 155 | 155 | { |
| 156 | 156 | $this->primarykey = $primarykey; |
| 157 | 157 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | /** |
| 162 | 162 | * @param \Classes\Db\Constrant $dependece |
| 163 | 163 | */ |
| 164 | - public function addDependece ( Constrant $dependece ) |
|
| 164 | + public function addDependece(Constrant $dependece) |
|
| 165 | 165 | { |
| 166 | 166 | $this->dependences[] = $dependece; |
| 167 | 167 | |
@@ -175,19 +175,19 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @return $this |
| 177 | 177 | */ |
| 178 | - public function createDependece ( $constraint_name , $table_name , $column_name , $schema = null ) |
|
| 178 | + public function createDependece($constraint_name, $table_name, $column_name, $schema = null) |
|
| 179 | 179 | { |
| 180 | - $objConstrantDependence = Constrant::getInstance () |
|
| 181 | - ->populate ( |
|
| 182 | - array ( |
|
| 183 | - 'constrant' => $constraint_name , |
|
| 184 | - 'schema' => $schema , |
|
| 185 | - 'table' => $table_name , |
|
| 180 | + $objConstrantDependence = Constrant::getInstance() |
|
| 181 | + ->populate( |
|
| 182 | + array( |
|
| 183 | + 'constrant' => $constraint_name, |
|
| 184 | + 'schema' => $schema, |
|
| 185 | + 'table' => $table_name, |
|
| 186 | 186 | 'column' => $column_name |
| 187 | 187 | ) |
| 188 | 188 | ); |
| 189 | 189 | |
| 190 | - $this->addDependece ( $objConstrantDependence ); |
|
| 190 | + $this->addDependece($objConstrantDependence); |
|
| 191 | 191 | |
| 192 | 192 | return $this; |
| 193 | 193 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | /** |
| 196 | 196 | * @param \Classes\Db\Constrant $reference |
| 197 | 197 | */ |
| 198 | - public function addRefFk ( Constrant $reference ) |
|
| 198 | + public function addRefFk(Constrant $reference) |
|
| 199 | 199 | { |
| 200 | 200 | $this->refForeingkey = $reference; |
| 201 | 201 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | * |
| 208 | 208 | * @return \Classes\Db\Constrant |
| 209 | 209 | */ |
| 210 | - public function getFks () |
|
| 210 | + public function getFks() |
|
| 211 | 211 | { |
| 212 | 212 | return $this->refForeingkey; |
| 213 | 213 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * |
| 218 | 218 | * @return \Classes\Db\Constrant[] |
| 219 | 219 | */ |
| 220 | - public function getDependences () |
|
| 220 | + public function getDependences() |
|
| 221 | 221 | { |
| 222 | 222 | return $this->dependences; |
| 223 | 223 | } |
@@ -225,9 +225,9 @@ discard block |
||
| 225 | 225 | /** |
| 226 | 226 | * @return bool |
| 227 | 227 | */ |
| 228 | - public function hasDependences () |
|
| 228 | + public function hasDependences() |
|
| 229 | 229 | { |
| 230 | - return (bool) count ( $this->dependences ); |
|
| 230 | + return (bool) count($this->dependences); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | * |
| 236 | 236 | * @return \Classes\Db\Constrant[] |
| 237 | 237 | */ |
| 238 | - public function getPrimaryKey () |
|
| 238 | + public function getPrimaryKey() |
|
| 239 | 239 | { |
| 240 | 240 | return $this->primarykey; |
| 241 | 241 | } |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | /** |
| 244 | 244 | * |
| 245 | 245 | */ |
| 246 | - public function getMaxLength () |
|
| 246 | + public function getMaxLength() |
|
| 247 | 247 | { |
| 248 | 248 | return $this->max_length; |
| 249 | 249 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | /** |
| 252 | 252 | * @return bool |
| 253 | 253 | */ |
| 254 | - public function hasSequence () |
|
| 254 | + public function hasSequence() |
|
| 255 | 255 | { |
| 256 | 256 | return (bool) $this->sequence; |
| 257 | 257 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | /** |
| 260 | 260 | * @return string |
| 261 | 261 | */ |
| 262 | - public function getSequence () |
|
| 262 | + public function getSequence() |
|
| 263 | 263 | { |
| 264 | 264 | return $this->sequence; |
| 265 | 265 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | /** |
| 268 | 268 | * @param string $sequence |
| 269 | 269 | */ |
| 270 | - public function setSequence ( $sequence ) |
|
| 270 | + public function setSequence($sequence) |
|
| 271 | 271 | { |
| 272 | 272 | $this->sequence = $sequence; |
| 273 | 273 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | /** |
| 276 | 276 | * @return boolean |
| 277 | 277 | */ |
| 278 | - public function isNullable () |
|
| 278 | + public function isNullable() |
|
| 279 | 279 | { |
| 280 | 280 | return $this->nullable; |
| 281 | 281 | } |