@@ -3,22 +3,22 @@ |
||
| 3 | 3 | /** |
| 4 | 4 | * Mvc Model |
| 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 | namespace <?=$objTables->getNamespace()?>; |
| 18 | 18 | |
| 19 | 19 | use Phalcon\Mvc\Model; |
| 20 | 20 | |
| 21 | -abstract class <?=\Classes\Maker\AbstractMaker::getClassName ( $objTables->getName () )?> extends Model |
|
| 21 | +abstract class <?=\Classes\Maker\AbstractMaker::getClassName($objTables->getName())?> extends Model |
|
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | } |
| 25 | 25 | \ No newline at end of file |
@@ -20,13 +20,13 @@ |
||
| 20 | 20 | ; database host |
| 21 | 21 | host = <?= $host ?><?= "\n" ?> |
| 22 | 22 | ; database name |
| 23 | -database = "<?= isset( $database ) ? $database : '' ?>"<?= "\n" ?> |
|
| 23 | +database = "<?= isset($database) ? $database : '' ?>"<?= "\n" ?> |
|
| 24 | 24 | ; database schema name (one or more than one) |
| 25 | -<?= isset( $schema ) ? 'schema = ' . $schema : ';schema = public' ?><?= "\n" ?> |
|
| 25 | +<?= isset($schema) ? 'schema = ' . $schema : ';schema = public' ?><?= "\n" ?> |
|
| 26 | 26 | ; database user |
| 27 | -username = <?= isset( $username ) ? $username : '' ?><?= "\n" ?> |
|
| 27 | +username = <?= isset($username) ? $username : '' ?><?= "\n" ?> |
|
| 28 | 28 | ; database password |
| 29 | -password = <?= isset( $password ) ? $password : '' ?><?= "\n" ?> |
|
| 29 | +password = <?= isset($password) ? $password : '' ?><?= "\n" ?> |
|
| 30 | 30 | ; show status of implementation carried out after completing the process |
| 31 | 31 | status = false |
| 32 | 32 | ; specify where to create the files (default is current directory) |
@@ -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; |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | * @author Pedro Alarcao <[email protected]> |
| 23 | 23 | */ |
| 24 | - public function __construct () |
|
| 24 | + public function __construct() |
|
| 25 | 25 | { |
| 26 | 26 | } |
| 27 | 27 | |
@@ -45,28 +45,28 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | protected $column; |
| 47 | 47 | |
| 48 | - public function populate ( $array ) |
|
| 48 | + public function populate($array) |
|
| 49 | 49 | { |
| 50 | - if(isset($array[ 'schema' ])){ |
|
| 51 | - $this->schema = $array[ 'schema' ]; |
|
| 50 | + if (isset($array['schema'])) { |
|
| 51 | + $this->schema = $array['schema']; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $this->constrant = $array[ 'constrant' ]; |
|
| 55 | - $this->table = $array[ 'table' ]; |
|
| 56 | - $this->column = $array[ 'column' ]; |
|
| 54 | + $this->constrant = $array['constrant']; |
|
| 55 | + $this->table = $array['table']; |
|
| 56 | + $this->column = $array['column']; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - public function getDatabase(){} |
|
| 59 | + public function getDatabase() {} |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * @return string |
| 63 | 63 | */ |
| 64 | - public function getNameConstrant () |
|
| 64 | + public function getNameConstrant() |
|
| 65 | 65 | { |
| 66 | 66 | return $this->constrant; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function hasSchema () |
|
| 69 | + public function hasSchema() |
|
| 70 | 70 | { |
| 71 | 71 | return (bool) $this->schema; |
| 72 | 72 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | /** |
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | - public function getSchema () |
|
| 77 | + public function getSchema() |
|
| 78 | 78 | { |
| 79 | 79 | return $this->schema; |
| 80 | 80 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | /** |
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | - public function getTable () |
|
| 85 | + public function getTable() |
|
| 86 | 86 | { |
| 87 | 87 | return $this->table; |
| 88 | 88 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | /** |
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | - public function getColumn () |
|
| 93 | + public function getColumn() |
|
| 94 | 94 | { |
| 95 | 95 | return $this->column; |
| 96 | 96 | } |
@@ -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 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @type \Classes\Db\DbTable[][] |
| 59 | 59 | */ |
| 60 | - protected $objDbTables = array (); |
|
| 60 | + protected $objDbTables = array(); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * @var AbstractAdapter |
@@ -72,19 +72,19 @@ discard block |
||
| 72 | 72 | /** |
| 73 | 73 | * Popula as ForeingKeys do banco nos objetos |
| 74 | 74 | */ |
| 75 | - protected abstract function parseForeignKeys (); |
|
| 75 | + protected abstract function parseForeignKeys(); |
|
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | 78 | * cria um Array com nome das tabelas |
| 79 | 79 | */ |
| 80 | - protected abstract function parseTables (); |
|
| 80 | + protected abstract function parseTables(); |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * retorna o numero total de tabelas |
| 84 | 84 | * |
| 85 | 85 | * @return int |
| 86 | 86 | */ |
| 87 | - public abstract function getTotalTables (); |
|
| 87 | + public abstract function getTotalTables(); |
|
| 88 | 88 | |
| 89 | 89 | /** |
| 90 | 90 | * Retorna o Nome da Sequence da tabela |
@@ -94,23 +94,23 @@ discard block |
||
| 94 | 94 | * |
| 95 | 95 | * @return string |
| 96 | 96 | */ |
| 97 | - public abstract function getSequence ( $table , $column ); |
|
| 97 | + public abstract function getSequence($table, $column); |
|
| 98 | 98 | |
| 99 | 99 | /** |
| 100 | 100 | * @return array |
| 101 | 101 | */ |
| 102 | - public abstract function getListConstrant (); |
|
| 102 | + public abstract function getListConstrant(); |
|
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | 105 | * @param string $str |
| 106 | 106 | * |
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | - protected function convertTypeToPhp ( $str ) |
|
| 109 | + protected function convertTypeToPhp($str) |
|
| 110 | 110 | { |
| 111 | - if ( isset( $this->dataTypes[ $str ] ) ) |
|
| 111 | + if (isset($this->dataTypes[$str])) |
|
| 112 | 112 | { |
| 113 | - return $this->dataTypes[ $str ]; |
|
| 113 | + return $this->dataTypes[$str]; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | return 'string'; |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | /** |
| 120 | 120 | * @return string |
| 121 | 121 | */ |
| 122 | - public abstract function getPDOString (); |
|
| 122 | + public abstract function getPDOString(); |
|
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * @return string |
| 126 | 126 | */ |
| 127 | - public abstract function getPDOSocketString (); |
|
| 127 | + public abstract function getPDOSocketString(); |
|
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * @param $nameTable |
@@ -132,13 +132,13 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @return \Classes\Db\DbTable |
| 134 | 134 | */ |
| 135 | - public function createTable ( $nameTable , $schema = 0 ) |
|
| 135 | + public function createTable($nameTable, $schema = 0) |
|
| 136 | 136 | { |
| 137 | - $this->objDbTables[ $schema ][ trim ( $nameTable ) ] = new DbTable(); |
|
| 138 | - $this->objDbTables[ $schema ][ trim ( $nameTable ) ]->populate ( |
|
| 139 | - array ( |
|
| 140 | - 'table' => $nameTable , |
|
| 141 | - 'schema' => $schema , |
|
| 137 | + $this->objDbTables[$schema][trim($nameTable)] = new DbTable(); |
|
| 138 | + $this->objDbTables[$schema][trim($nameTable)]->populate( |
|
| 139 | + array( |
|
| 140 | + 'table' => $nameTable, |
|
| 141 | + 'schema' => $schema, |
|
| 142 | 142 | 'database' => $this->database |
| 143 | 143 | ) |
| 144 | 144 | ); |
@@ -151,14 +151,14 @@ discard block |
||
| 151 | 151 | * |
| 152 | 152 | * @return \Classes\Db\DbTable[] |
| 153 | 153 | */ |
| 154 | - public function getTables ( $schema = 0 ) |
|
| 154 | + public function getTables($schema = 0) |
|
| 155 | 155 | { |
| 156 | - if ( ! isset( $this->objDbTables[ $schema ] ) ) |
|
| 156 | + if ( ! isset($this->objDbTables[$schema])) |
|
| 157 | 157 | { |
| 158 | - return array (); |
|
| 158 | + return array(); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - return $this->objDbTables[ $schema ]; |
|
| 161 | + return $this->objDbTables[$schema]; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @return \Classes\Db\DbTable|null |
| 170 | 170 | */ |
| 171 | - public function getTable ( $nameTable , $schema = 0 ) |
|
| 171 | + public function getTable($nameTable, $schema = 0) |
|
| 172 | 172 | { |
| 173 | - if ( isset( $this->objDbTables[ $schema ][ trim ( $nameTable ) ] ) ) |
|
| 173 | + if (isset($this->objDbTables[$schema][trim($nameTable)])) |
|
| 174 | 174 | { |
| 175 | - return $this->objDbTables[ $schema ][ trim ( $nameTable ) ]; |
|
| 175 | + return $this->objDbTables[$schema][trim($nameTable)]; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return null; |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return bool |
| 186 | 186 | */ |
| 187 | - public function hasTable ( $nameTable , $schema = 0 ) |
|
| 187 | + public function hasTable($nameTable, $schema = 0) |
|
| 188 | 188 | { |
| 189 | - if ( isset( $this->objDbTables[ $schema ][ trim ( $nameTable ) ] ) ) |
|
| 189 | + if (isset($this->objDbTables[$schema][trim($nameTable)])) |
|
| 190 | 190 | { |
| 191 | 191 | return true; |
| 192 | 192 | } |
@@ -199,64 +199,64 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return array[] |
| 201 | 201 | */ |
| 202 | - public abstract function getListColumns (); |
|
| 202 | + public abstract function getListColumns(); |
|
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | 205 | * Retorna um Array com nome das tabelas |
| 206 | 206 | * |
| 207 | 207 | * @return string[] |
| 208 | 208 | */ |
| 209 | - public abstract function getListNameTable (); |
|
| 209 | + public abstract function getListNameTable(); |
|
| 210 | 210 | |
| 211 | 211 | /** |
| 212 | 212 | * @param \Classes\AdapterConfig\AbstractAdapter $adapterConfig |
| 213 | 213 | */ |
| 214 | - public function __construct ( AbstractAdapter $adapterConfig ) |
|
| 214 | + public function __construct(AbstractAdapter $adapterConfig) |
|
| 215 | 215 | { |
| 216 | 216 | $this->config = $adapterConfig; |
| 217 | - $this->host = $adapterConfig->getHost (); |
|
| 218 | - $this->database = $adapterConfig->getDatabase (); |
|
| 219 | - $this->port = $adapterConfig->hasPort () ? $adapterConfig->getPort () |
|
| 217 | + $this->host = $adapterConfig->getHost(); |
|
| 218 | + $this->database = $adapterConfig->getDatabase(); |
|
| 219 | + $this->port = $adapterConfig->hasPort() ? $adapterConfig->getPort() |
|
| 220 | 220 | : $this->port; |
| 221 | - $this->username = $adapterConfig->getUser (); |
|
| 222 | - $this->password = $adapterConfig->getPassword (); |
|
| 223 | - $this->socket = $adapterConfig->getSocket (); |
|
| 221 | + $this->username = $adapterConfig->getUser(); |
|
| 222 | + $this->password = $adapterConfig->getPassword(); |
|
| 223 | + $this->socket = $adapterConfig->getSocket(); |
|
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
| 228 | 228 | * Executa as consultas do banco de dados |
| 229 | 229 | */ |
| 230 | - public function runDatabase () |
|
| 230 | + public function runDatabase() |
|
| 231 | 231 | { |
| 232 | - $this->parseTables (); |
|
| 233 | - $this->parseForeignKeys (); |
|
| 232 | + $this->parseTables(); |
|
| 233 | + $this->parseForeignKeys(); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | 237 | * |
| 238 | 238 | * @return \PDO |
| 239 | 239 | */ |
| 240 | - public function getPDO () |
|
| 240 | + public function getPDO() |
|
| 241 | 241 | { |
| 242 | - if ( is_null ( $this->_pdo ) ) |
|
| 242 | + if (is_null($this->_pdo)) |
|
| 243 | 243 | { |
| 244 | - if ( ! empty( $this->socket ) ) |
|
| 244 | + if ( ! empty($this->socket)) |
|
| 245 | 245 | { |
| 246 | - $pdoString = $this->getPDOSocketString (); |
|
| 246 | + $pdoString = $this->getPDOSocketString(); |
|
| 247 | 247 | } else |
| 248 | 248 | { |
| 249 | - $pdoString = $this->getPDOString (); |
|
| 249 | + $pdoString = $this->getPDOString(); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | try |
| 253 | 253 | { |
| 254 | - $this->_pdo = new \PDO ( |
|
| 255 | - $pdoString , $this->username , $this->password |
|
| 254 | + $this->_pdo = new \PDO( |
|
| 255 | + $pdoString, $this->username, $this->password |
|
| 256 | 256 | ); |
| 257 | - } catch ( \Exception $e ) |
|
| 257 | + } catch (\Exception $e) |
|
| 258 | 258 | { |
| 259 | - die ( "pdo error: " . $e->getMessage () . "\n" ); |
|
| 259 | + die ("pdo error: " . $e->getMessage() . "\n"); |
|
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | 262 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | if ( $this->hasTable ( $key , $schema ) ) |
| 70 | 70 | { |
| 71 | 71 | $column = $this->getTable ( $key , $schema ) |
| 72 | - ->getColumn ( $constrant[ "column_name" ] ); |
|
| 72 | + ->getColumn ( $constrant[ "column_name" ] ); |
|
| 73 | 73 | if ( $column ) |
| 74 | 74 | { |
| 75 | 75 | $objConstrant = new Constrant(); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | if ( $this->hasTable ( $key , $schema ) ) |
| 110 | 110 | { |
| 111 | 111 | $column = $this->getTable ( $key , $schema ) |
| 112 | - ->getColumn ( $constrant[ "foreign_column" ] ); |
|
| 112 | + ->getColumn ( $constrant[ "foreign_column" ] ); |
|
| 113 | 113 | |
| 114 | 114 | if ( $column ) |
| 115 | 115 | { |
@@ -151,16 +151,16 @@ discard block |
||
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | $this->getTable ( $key , $schema ) |
| 154 | - ->createColumn ( $table [ 'column_name' ] ) |
|
| 155 | - ->getColumn ( $table [ 'column_name' ] ) |
|
| 156 | - ->populate ( |
|
| 157 | - array ( |
|
| 158 | - 'name' => $table [ 'column_name' ] , |
|
| 159 | - 'type' => $this->convertTypeToPhp ( $table[ 'data_type' ] ) , |
|
| 160 | - 'nullable' => ( $table[ 'is_nullable' ] == 'YES' ) , |
|
| 161 | - 'max_length' => $table[ 'max_length' ] |
|
| 162 | - ) |
|
| 163 | - ); |
|
| 154 | + ->createColumn ( $table [ 'column_name' ] ) |
|
| 155 | + ->getColumn ( $table [ 'column_name' ] ) |
|
| 156 | + ->populate ( |
|
| 157 | + array ( |
|
| 158 | + 'name' => $table [ 'column_name' ] , |
|
| 159 | + 'type' => $this->convertTypeToPhp ( $table[ 'data_type' ] ) , |
|
| 160 | + 'nullable' => ( $table[ 'is_nullable' ] == 'YES' ) , |
|
| 161 | + 'max_length' => $table[ 'max_length' ] |
|
| 162 | + ) |
|
| 163 | + ); |
|
| 164 | 164 | |
| 165 | 165 | $this->getTable ( $key , $schema )->setNamespace ( |
| 166 | 166 | $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | public function getSequence ( $table , $column ) |
| 287 | 287 | { |
| 288 | 288 | $return = $this->getPDO () |
| 289 | - ->query ( "select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';" ) |
|
| 290 | - ->fetch ( \PDO::FETCH_ASSOC ); |
|
| 289 | + ->query ( "select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';" ) |
|
| 290 | + ->fetch ( \PDO::FETCH_ASSOC ); |
|
| 291 | 291 | |
| 292 | 292 | if ( ! $return ) |
| 293 | 293 | { |
@@ -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,44 +55,44 @@ discard block |
||
| 55 | 55 | /** |
| 56 | 56 | * @inheritDoc |
| 57 | 57 | */ |
| 58 | - protected function parseForeignKeys () |
|
| 58 | + protected function parseForeignKeys() |
|
| 59 | 59 | { |
| 60 | 60 | $schema = 0; |
| 61 | - foreach ( $this->getListConstrant () as $constrant ) |
|
| 61 | + foreach ($this->getListConstrant() as $constrant) |
|
| 62 | 62 | { |
| 63 | 63 | |
| 64 | - if ( $constrant[ 'constraint_type' ] == "FOREIGN KEY" |
|
| 65 | - || $constrant[ 'constraint_type' ] == "PRIMARY KEY" |
|
| 64 | + if ($constrant['constraint_type'] == "FOREIGN KEY" |
|
| 65 | + || $constrant['constraint_type'] == "PRIMARY KEY" |
|
| 66 | 66 | ) |
| 67 | 67 | { |
| 68 | - $key = $constrant [ 'table_name' ]; |
|
| 69 | - if ( $this->hasTable ( $key , $schema ) ) |
|
| 68 | + $key = $constrant ['table_name']; |
|
| 69 | + if ($this->hasTable($key, $schema)) |
|
| 70 | 70 | { |
| 71 | - $column = $this->getTable ( $key , $schema ) |
|
| 72 | - ->getColumn ( $constrant[ "column_name" ] ); |
|
| 73 | - if ( $column ) |
|
| 71 | + $column = $this->getTable($key, $schema) |
|
| 72 | + ->getColumn($constrant["column_name"]); |
|
| 73 | + if ($column) |
|
| 74 | 74 | { |
| 75 | 75 | $objConstrant = new Constrant(); |
| 76 | - $objConstrant->populate ( |
|
| 77 | - array ( |
|
| 78 | - 'constrant' => $constrant[ 'constraint_name' ] , |
|
| 79 | - 'table' => $constrant[ 'foreign_table' ] , |
|
| 80 | - 'column' => $constrant[ 'foreign_column' ] |
|
| 76 | + $objConstrant->populate( |
|
| 77 | + array( |
|
| 78 | + 'constrant' => $constrant['constraint_name'], |
|
| 79 | + 'table' => $constrant['foreign_table'], |
|
| 80 | + 'column' => $constrant['foreign_column'] |
|
| 81 | 81 | ) |
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | 84 | |
| 85 | - switch ( $constrant[ 'constraint_type' ] ) |
|
| 85 | + switch ($constrant['constraint_type']) |
|
| 86 | 86 | { |
| 87 | 87 | case "FOREIGN KEY": |
| 88 | - $column->addRefFk ( $objConstrant ); |
|
| 88 | + $column->addRefFk($objConstrant); |
|
| 89 | 89 | break; |
| 90 | 90 | case"PRIMARY KEY": |
| 91 | - $column->setPrimaryKey ( $objConstrant ); |
|
| 92 | - $column->setSequence ( |
|
| 93 | - $this->getSequence ( |
|
| 94 | - $key , |
|
| 95 | - $constrant[ "column_name" ] |
|
| 91 | + $column->setPrimaryKey($objConstrant); |
|
| 92 | + $column->setSequence( |
|
| 93 | + $this->getSequence( |
|
| 94 | + $key, |
|
| 95 | + $constrant["column_name"] |
|
| 96 | 96 | ) |
| 97 | 97 | ); |
| 98 | 98 | |
@@ -100,28 +100,28 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | - unset( $key , $column ); |
|
| 103 | + unset($key, $column); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - if ( $constrant[ 'constraint_type' ] == "FOREIGN KEY" ) |
|
| 106 | + if ($constrant['constraint_type'] == "FOREIGN KEY") |
|
| 107 | 107 | { |
| 108 | - $key = $constrant [ 'foreign_table' ]; |
|
| 109 | - if ( $this->hasTable ( $key , $schema ) ) |
|
| 108 | + $key = $constrant ['foreign_table']; |
|
| 109 | + if ($this->hasTable($key, $schema)) |
|
| 110 | 110 | { |
| 111 | - $column = $this->getTable ( $key , $schema ) |
|
| 112 | - ->getColumn ( $constrant[ "foreign_column" ] ); |
|
| 111 | + $column = $this->getTable($key, $schema) |
|
| 112 | + ->getColumn($constrant["foreign_column"]); |
|
| 113 | 113 | |
| 114 | - if ( $column ) |
|
| 114 | + if ($column) |
|
| 115 | 115 | { |
| 116 | - $column->createDependece ( |
|
| 117 | - $constrant[ 'constraint_name' ] , |
|
| 118 | - $constrant[ 'table_name' ] , |
|
| 119 | - $constrant[ 'column_name' ] , |
|
| 120 | - $constrant[ 'table_schema' ] |
|
| 116 | + $column->createDependece( |
|
| 117 | + $constrant['constraint_name'], |
|
| 118 | + $constrant['table_name'], |
|
| 119 | + $constrant['column_name'], |
|
| 120 | + $constrant['table_schema'] |
|
| 121 | 121 | ); |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | - unset( $key , $column ); |
|
| 124 | + unset($key, $column); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -134,36 +134,36 @@ discard block |
||
| 134 | 134 | /** |
| 135 | 135 | * @inheritDoc |
| 136 | 136 | */ |
| 137 | - public function parseTables () |
|
| 137 | + public function parseTables() |
|
| 138 | 138 | { |
| 139 | - if ( ! empty( $this->objDbTables ) ) |
|
| 139 | + if ( ! empty($this->objDbTables)) |
|
| 140 | 140 | { |
| 141 | 141 | return $this->objDbTables; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | $schema = 0; |
| 145 | - foreach ( $this->getListColumns () as $table ) |
|
| 145 | + foreach ($this->getListColumns() as $table) |
|
| 146 | 146 | { |
| 147 | - $key = $table [ 'table_name' ]; |
|
| 148 | - if ( ! $this->hasTable ( $key , $schema ) ) |
|
| 147 | + $key = $table ['table_name']; |
|
| 148 | + if ( ! $this->hasTable($key, $schema)) |
|
| 149 | 149 | { |
| 150 | - $this->createTable ( $key , $schema ); |
|
| 150 | + $this->createTable($key, $schema); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $this->getTable ( $key , $schema ) |
|
| 154 | - ->createColumn ( $table [ 'column_name' ] ) |
|
| 155 | - ->getColumn ( $table [ 'column_name' ] ) |
|
| 156 | - ->populate ( |
|
| 157 | - array ( |
|
| 158 | - 'name' => $table [ 'column_name' ] , |
|
| 159 | - 'type' => $this->convertTypeToPhp ( $table[ 'data_type' ] ) , |
|
| 160 | - 'nullable' => ( $table[ 'is_nullable' ] == 'YES' ) , |
|
| 161 | - 'max_length' => $table[ 'max_length' ] |
|
| 153 | + $this->getTable($key, $schema) |
|
| 154 | + ->createColumn($table ['column_name']) |
|
| 155 | + ->getColumn($table ['column_name']) |
|
| 156 | + ->populate( |
|
| 157 | + array( |
|
| 158 | + 'name' => $table ['column_name'], |
|
| 159 | + 'type' => $this->convertTypeToPhp($table['data_type']), |
|
| 160 | + 'nullable' => ($table['is_nullable'] == 'YES'), |
|
| 161 | + 'max_length' => $table['max_length'] |
|
| 162 | 162 | ) |
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | - $this->getTable ( $key , $schema )->setNamespace ( |
|
| 166 | - $this->config->createClassNamespace ( $this->getTable ( $key , $schema ) ) |
|
| 165 | + $this->getTable($key, $schema)->setNamespace( |
|
| 166 | + $this->config->createClassNamespace($this->getTable($key, $schema)) |
|
| 167 | 167 | ); |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -172,12 +172,12 @@ discard block |
||
| 172 | 172 | * @inheritDoc |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function getPDOString () |
|
| 175 | + public function getPDOString() |
|
| 176 | 176 | { |
| 177 | - return sprintf ( |
|
| 178 | - "mysql:host=%s;port=%s;dbname=%s" , |
|
| 179 | - $this->host , |
|
| 180 | - $this->port , |
|
| 177 | + return sprintf( |
|
| 178 | + "mysql:host=%s;port=%s;dbname=%s", |
|
| 179 | + $this->host, |
|
| 180 | + $this->port, |
|
| 181 | 181 | $this->database |
| 182 | 182 | |
| 183 | 183 | ); |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | * @inheritDoc |
| 188 | 188 | * @return string |
| 189 | 189 | */ |
| 190 | - public function getPDOSocketString () |
|
| 190 | + public function getPDOSocketString() |
|
| 191 | 191 | { |
| 192 | - return sprintf ( |
|
| 193 | - "mysql:unix_socket=%s;dbname=%s" , |
|
| 194 | - $this->socket , |
|
| 192 | + return sprintf( |
|
| 193 | + "mysql:unix_socket=%s;dbname=%s", |
|
| 194 | + $this->socket, |
|
| 195 | 195 | $this->database |
| 196 | 196 | |
| 197 | 197 | ); |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | * @inheritDoc |
| 202 | 202 | * @return string[] |
| 203 | 203 | */ |
| 204 | - public function getListNameTable () |
|
| 204 | + public function getListNameTable() |
|
| 205 | 205 | { |
| 206 | - if ( empty( $this->tableList ) ) |
|
| 206 | + if (empty($this->tableList)) |
|
| 207 | 207 | { |
| 208 | - $this->tableList = $this->getPDO ()->query ( |
|
| 208 | + $this->tableList = $this->getPDO()->query( |
|
| 209 | 209 | "show tables" |
| 210 | - )->fetchAll (); |
|
| 210 | + )->fetchAll(); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | return $this->tableList; |
@@ -218,10 +218,10 @@ discard block |
||
| 218 | 218 | * |
| 219 | 219 | * @return array[] |
| 220 | 220 | */ |
| 221 | - public function getListColumns () |
|
| 221 | + public function getListColumns() |
|
| 222 | 222 | { |
| 223 | 223 | |
| 224 | - return $this->getPDO ()->query ( |
|
| 224 | + return $this->getPDO()->query( |
|
| 225 | 225 | "select |
| 226 | 226 | table_schema, |
| 227 | 227 | table_name, |
@@ -232,15 +232,15 @@ discard block |
||
| 232 | 232 | from information_schema.columns |
| 233 | 233 | where table_schema IN ('{$this->database}') |
| 234 | 234 | order by table_name,ordinal_position" |
| 235 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 235 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
| 239 | 239 | * @return array |
| 240 | 240 | */ |
| 241 | - public function getListConstrant () |
|
| 241 | + public function getListConstrant() |
|
| 242 | 242 | { |
| 243 | - return $this->getPDO ()->query ( |
|
| 243 | + return $this->getPDO()->query( |
|
| 244 | 244 | "SELECT distinct |
| 245 | 245 | i.constraint_type, |
| 246 | 246 | k.constraint_name, |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | WHERE |
| 257 | 257 | i.TABLE_SCHEMA IN ('{$this->database}') AND i.CONSTRAINT_TYPE IN ('FOREIGN KEY', 'PRIMARY KEY' ) |
| 258 | 258 | order by k.table_schema, k.table_name;" |
| 259 | - )->fetchAll ( \PDO::FETCH_ASSOC ); |
|
| 259 | + )->fetchAll(\PDO::FETCH_ASSOC); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | * |
| 265 | 265 | * @return int |
| 266 | 266 | */ |
| 267 | - public function getTotalTables () |
|
| 267 | + public function getTotalTables() |
|
| 268 | 268 | { |
| 269 | - if ( empty( $this->totalTables ) ) |
|
| 269 | + if (empty($this->totalTables)) |
|
| 270 | 270 | { |
| 271 | 271 | |
| 272 | - $this->totalTables = $this->getPDO ()->query ( |
|
| 272 | + $this->totalTables = $this->getPDO()->query( |
|
| 273 | 273 | "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '{$this->database}'" |
| 274 | - )->fetchColumn (); |
|
| 274 | + )->fetchColumn(); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | return (int) $this->totalTables; |
@@ -283,13 +283,13 @@ discard block |
||
| 283 | 283 | * @param $table |
| 284 | 284 | * @param $column |
| 285 | 285 | */ |
| 286 | - public function getSequence ( $table , $column ) |
|
| 286 | + public function getSequence($table, $column) |
|
| 287 | 287 | { |
| 288 | - $return = $this->getPDO () |
|
| 289 | - ->query ( "select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';" ) |
|
| 290 | - ->fetch ( \PDO::FETCH_ASSOC ); |
|
| 288 | + $return = $this->getPDO() |
|
| 289 | + ->query("select * from information_schema.columns where extra like '%auto_increment%' and TABLE_SCHEMA='{$this->database}' AND TABLE_NAME='{$table}' AND COLUMN_NAME='{$column}';") |
|
| 290 | + ->fetch(\PDO::FETCH_ASSOC); |
|
| 291 | 291 | |
| 292 | - if ( ! $return ) |
|
| 292 | + if ( ! $return) |
|
| 293 | 293 | { |
| 294 | 294 | return; |
| 295 | 295 | } |