@@ -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 | } |
@@ -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 | } |
@@ -46,6 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Analisa os caminhos das pastas base |
| 49 | + * @param string $basePath |
|
| 49 | 50 | */ |
| 50 | 51 | public function parseLocation ( $basePath ) |
| 51 | 52 | { |
@@ -173,6 +174,9 @@ discard block |
||
| 173 | 174 | echo "\n\033[1;32mSuccessfully process finished!\n\033[0m"; |
| 174 | 175 | } |
| 175 | 176 | |
| 177 | + /** |
|
| 178 | + * @param integer $countFiles |
|
| 179 | + */ |
|
| 176 | 180 | private function reportProcess ( $countFiles ) |
| 177 | 181 | { |
| 178 | 182 | if ( $this->config->isStatusEnabled () ) |
@@ -223,6 +227,7 @@ discard block |
||
| 223 | 227 | * parse a tpl file and return the result |
| 224 | 228 | * |
| 225 | 229 | * @param String $tplFile |
| 230 | + * @param AbstractAdapter $objMakeFile |
|
| 226 | 231 | * |
| 227 | 232 | * @return String |
| 228 | 233 | */ |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | /** |
| 19 | 19 | * @type string[] |
| 20 | 20 | */ |
| 21 | - public $location = array (); |
|
| 21 | + public $location = array(); |
|
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * caminho de pastas Base |
@@ -37,161 +37,161 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | private $driver; |
| 39 | 39 | |
| 40 | - public function __construct ( Config $config ) |
|
| 40 | + public function __construct(Config $config) |
|
| 41 | 41 | { |
| 42 | - $this->config = $config->getAdapterConfig (); |
|
| 43 | - $this->driver = $config->getAdapterDriver (); |
|
| 44 | - $this->parseLocation ( $config->_basePath ); |
|
| 42 | + $this->config = $config->getAdapterConfig(); |
|
| 43 | + $this->driver = $config->getAdapterDriver(); |
|
| 44 | + $this->parseLocation($config->_basePath); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Analisa os caminhos das pastas base |
| 49 | 49 | */ |
| 50 | - public function parseLocation ( $basePath ) |
|
| 50 | + public function parseLocation($basePath) |
|
| 51 | 51 | { |
| 52 | 52 | |
| 53 | - $arrBase = array ( |
|
| 54 | - $basePath , |
|
| 53 | + $arrBase = array( |
|
| 54 | + $basePath, |
|
| 55 | 55 | $this->config->path |
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | - $this->baseLocation = implode ( DIRECTORY_SEPARATOR , array_filter ( $arrBase ) ); |
|
| 58 | + $this->baseLocation = implode(DIRECTORY_SEPARATOR, array_filter($arrBase)); |
|
| 59 | 59 | |
| 60 | 60 | # pasta com nome do driver do banco |
| 61 | 61 | $driverBase = ''; |
| 62 | - if ( (bool) @$this->config->{"folder-database"} ) |
|
| 62 | + if ((bool) @$this->config->{"folder-database"} ) |
|
| 63 | 63 | { |
| 64 | - $classDriver = explode ( '\\' , get_class ( $this->driver ) ); |
|
| 65 | - $driverBase = end ( $classDriver ); |
|
| 64 | + $classDriver = explode('\\', get_class($this->driver)); |
|
| 65 | + $driverBase = end($classDriver); |
|
| 66 | 66 | } |
| 67 | 67 | $folderName = ''; |
| 68 | - if ( (bool) @$this->config->{"folder-name"} ) |
|
| 68 | + if ((bool) @$this->config->{"folder-name"} ) |
|
| 69 | 69 | { |
| 70 | - $folderName = $this->getClassName ( trim ( $this->config->{"folder-name"} ) ); |
|
| 70 | + $folderName = $this->getClassName(trim($this->config->{"folder-name"} )); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - if ( $this->config->hasSchemas () ) |
|
| 73 | + if ($this->config->hasSchemas()) |
|
| 74 | 74 | { |
| 75 | 75 | |
| 76 | - $schemas = $this->config->getSchemas (); |
|
| 77 | - foreach ( $schemas as $schema ) |
|
| 76 | + $schemas = $this->config->getSchemas(); |
|
| 77 | + foreach ($schemas as $schema) |
|
| 78 | 78 | { |
| 79 | - $arrUrl = array ( |
|
| 79 | + $arrUrl = array( |
|
| 80 | 80 | $this->baseLocation, |
| 81 | 81 | $driverBase, |
| 82 | 82 | $folderName, |
| 83 | - $this->getClassName ( $schema ) |
|
| 83 | + $this->getClassName($schema) |
|
| 84 | 84 | ); |
| 85 | 85 | |
| 86 | - $this->location[ $schema ] = implode ( DIRECTORY_SEPARATOR , array_filter ( $arrUrl ) ); |
|
| 87 | - unset( $arrUrl ); |
|
| 86 | + $this->location[$schema] = implode(DIRECTORY_SEPARATOR, array_filter($arrUrl)); |
|
| 87 | + unset($arrUrl); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | |
| 91 | 91 | } else |
| 92 | 92 | { |
| 93 | - $baseLocation = implode ( |
|
| 94 | - DIRECTORY_SEPARATOR , array_filter ( array ( |
|
| 95 | - $this->baseLocation , |
|
| 96 | - $driverBase , |
|
| 97 | - $folderName , |
|
| 98 | - $this->getClassName ( $this->getConfig ()->getDatabase () ) |
|
| 93 | + $baseLocation = implode( |
|
| 94 | + DIRECTORY_SEPARATOR, array_filter(array( |
|
| 95 | + $this->baseLocation, |
|
| 96 | + $driverBase, |
|
| 97 | + $folderName, |
|
| 98 | + $this->getClassName($this->getConfig()->getDatabase()) |
|
| 99 | 99 | ) |
| 100 | 100 | ) |
| 101 | 101 | ); |
| 102 | - $this->location = array ( $baseLocation ); |
|
| 102 | + $this->location = array($baseLocation); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | 107 | * @return AdapterConfig\AbstractAdapter |
| 108 | 108 | */ |
| 109 | - public function getConfig () |
|
| 109 | + public function getConfig() |
|
| 110 | 110 | { |
| 111 | 111 | return $this->config; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /* Get current time */ |
| 115 | - public function startTime () |
|
| 115 | + public function startTime() |
|
| 116 | 116 | { |
| 117 | 117 | echo "Starting..\n"; |
| 118 | - $this->startTime = microtime ( true ); |
|
| 118 | + $this->startTime = microtime(true); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - private function getRunTime () |
|
| 121 | + private function getRunTime() |
|
| 122 | 122 | { |
| 123 | - return round ( ( microtime ( true ) - $this->startTime ) , 3 ); |
|
| 123 | + return round((microtime(true) - $this->startTime), 3); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | 127 | * Executa o Make, criando arquivos e Diretorios |
| 128 | 128 | */ |
| 129 | - public function run () |
|
| 129 | + public function run() |
|
| 130 | 130 | { |
| 131 | - $this->startTime (); |
|
| 132 | - $this->driver->runDatabase (); |
|
| 133 | - $max = $this->driver->getTotalTables () * count ( $this->factoryMakerFile () ); |
|
| 131 | + $this->startTime(); |
|
| 132 | + $this->driver->runDatabase(); |
|
| 133 | + $max = $this->driver->getTotalTables() * count($this->factoryMakerFile()); |
|
| 134 | 134 | $cur = 0; |
| 135 | 135 | |
| 136 | 136 | |
| 137 | - foreach ( $this->location as $schema => $location ) |
|
| 137 | + foreach ($this->location as $schema => $location) |
|
| 138 | 138 | { |
| 139 | - foreach ( $this->factoryMakerFile () as $objMakeFile ) |
|
| 139 | + foreach ($this->factoryMakerFile() as $objMakeFile) |
|
| 140 | 140 | { |
| 141 | - $path = $location . DIRECTORY_SEPARATOR . $objMakeFile->getPastName (); |
|
| 142 | - self::makeDir ( $path ); |
|
| 141 | + $path = $location . DIRECTORY_SEPARATOR . $objMakeFile->getPastName(); |
|
| 142 | + self::makeDir($path); |
|
| 143 | 143 | |
| 144 | - if ( $objMakeFile->getParentFileTpl () != '' ) |
|
| 144 | + if ($objMakeFile->getParentFileTpl() != '') |
|
| 145 | 145 | { |
| 146 | 146 | $fileAbstract = $this->baseLocation |
| 147 | 147 | . DIRECTORY_SEPARATOR |
| 148 | - . $objMakeFile->getParentClass () . '.php'; |
|
| 148 | + . $objMakeFile->getParentClass() . '.php'; |
|
| 149 | 149 | |
| 150 | - $tplAbstract = $this->getParsedTplContents ( $objMakeFile->getParentFileTpl () ); |
|
| 151 | - self::makeSourcer ( $fileAbstract , $tplAbstract , $objMakeFile->isOverwrite () ); |
|
| 152 | - unset( $fileAbstract , $tplAbstract ); |
|
| 150 | + $tplAbstract = $this->getParsedTplContents($objMakeFile->getParentFileTpl()); |
|
| 151 | + self::makeSourcer($fileAbstract, $tplAbstract, $objMakeFile->isOverwrite()); |
|
| 152 | + unset($fileAbstract, $tplAbstract); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - foreach ( $this->driver->getTables ( $schema ) as $key => $objTables ) |
|
| 155 | + foreach ($this->driver->getTables($schema) as $key => $objTables) |
|
| 156 | 156 | { |
| 157 | - $total = ceil ( $cur / $max ) * 100; |
|
| 158 | - printf ( "\r Creating: %6.2f%%" , $total ); |
|
| 159 | - $cur ++; |
|
| 157 | + $total = ceil($cur / $max) * 100; |
|
| 158 | + printf("\r Creating: %6.2f%%", $total); |
|
| 159 | + $cur++; |
|
| 160 | 160 | |
| 161 | 161 | $file = $path |
| 162 | 162 | . DIRECTORY_SEPARATOR |
| 163 | - . self::getClassName ( $objTables->getName () ) |
|
| 163 | + . self::getClassName($objTables->getName()) |
|
| 164 | 164 | . '.php'; |
| 165 | 165 | |
| 166 | 166 | |
| 167 | - $tpl = $this->getParsedTplContents ( |
|
| 168 | - $objMakeFile->getFileTpl () , |
|
| 169 | - $objMakeFile->parseRelation ( $this , $objTables ) |
|
| 170 | - , $objTables , $objMakeFile |
|
| 167 | + $tpl = $this->getParsedTplContents( |
|
| 168 | + $objMakeFile->getFileTpl(), |
|
| 169 | + $objMakeFile->parseRelation($this, $objTables) |
|
| 170 | + , $objTables, $objMakeFile |
|
| 171 | 171 | |
| 172 | 172 | ); |
| 173 | - self::makeSourcer ( $file , $tpl , $objMakeFile->isOverwrite () ); |
|
| 173 | + self::makeSourcer($file, $tpl, $objMakeFile->isOverwrite()); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - $this->reportProcess ( $cur ); |
|
| 179 | + $this->reportProcess($cur); |
|
| 180 | 180 | echo "\n\033[1;32mSuccessfully process finished!\n\033[0m"; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - private function reportProcess ( $countFiles ) |
|
| 183 | + private function reportProcess($countFiles) |
|
| 184 | 184 | { |
| 185 | - if ( $this->config->isStatusEnabled () ) |
|
| 185 | + if ($this->config->isStatusEnabled()) |
|
| 186 | 186 | { |
| 187 | - $databases = count ( $this->location ); |
|
| 188 | - $countDir = $this->countDiretory (); |
|
| 189 | - $totalTable = $this->driver->getTotalTables (); |
|
| 187 | + $databases = count($this->location); |
|
| 188 | + $countDir = $this->countDiretory(); |
|
| 189 | + $totalTable = $this->driver->getTotalTables(); |
|
| 190 | 190 | echo "\n------"; |
| 191 | - printf ( "\n\r-Files generated:%s" , $countFiles ); |
|
| 192 | - printf ( "\n\r-Diretory generated:%s" , $databases * $countDir ); |
|
| 193 | - printf ( "\n\r-Scanned tables:%s" , $totalTable ); |
|
| 194 | - printf ( "\n\r-Execution time: %ssec" , $this->getRunTime () ); |
|
| 191 | + printf("\n\r-Files generated:%s", $countFiles); |
|
| 192 | + printf("\n\r-Diretory generated:%s", $databases * $countDir); |
|
| 193 | + printf("\n\r-Scanned tables:%s", $totalTable); |
|
| 194 | + printf("\n\r-Execution time: %ssec", $this->getRunTime()); |
|
| 195 | 195 | echo "\n------"; |
| 196 | 196 | } |
| 197 | 197 | } |
@@ -201,9 +201,9 @@ discard block |
||
| 201 | 201 | * |
| 202 | 202 | * @return AbstractAdapter[] |
| 203 | 203 | */ |
| 204 | - public function factoryMakerFile () |
|
| 204 | + public function factoryMakerFile() |
|
| 205 | 205 | { |
| 206 | - return $this->config->getMakeFileInstances (); |
|
| 206 | + return $this->config->getMakeFileInstances(); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -211,14 +211,14 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @return int |
| 213 | 213 | */ |
| 214 | - public function countDiretory () |
|
| 214 | + public function countDiretory() |
|
| 215 | 215 | { |
| 216 | 216 | $dir = 0; |
| 217 | - foreach ( $this->factoryMakerFile () as $abstractAdapter ) |
|
| 217 | + foreach ($this->factoryMakerFile() as $abstractAdapter) |
|
| 218 | 218 | { |
| 219 | - if ( $abstractAdapter->hasDiretory () ) |
|
| 219 | + if ($abstractAdapter->hasDiretory()) |
|
| 220 | 220 | { |
| 221 | - $dir ++; |
|
| 221 | + $dir++; |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | |
@@ -233,23 +233,23 @@ discard block |
||
| 233 | 233 | * |
| 234 | 234 | * @return String |
| 235 | 235 | */ |
| 236 | - protected function getParsedTplContents ( $tplFile , $vars = array () , \Classes\Db\DbTable $objTables = null , $objMakeFile = null ) |
|
| 236 | + protected function getParsedTplContents($tplFile, $vars = array(), \Classes\Db\DbTable $objTables = null, $objMakeFile = null) |
|
| 237 | 237 | { |
| 238 | 238 | |
| 239 | - $arrUrl = array ( |
|
| 240 | - __DIR__ , |
|
| 241 | - 'templates' , |
|
| 242 | - $this->config->framework , |
|
| 239 | + $arrUrl = array( |
|
| 240 | + __DIR__, |
|
| 241 | + 'templates', |
|
| 242 | + $this->config->framework, |
|
| 243 | 243 | $tplFile |
| 244 | 244 | ); |
| 245 | 245 | |
| 246 | - $filePath = implode ( DIRECTORY_SEPARATOR , filter_var_array ( $arrUrl ) ); |
|
| 246 | + $filePath = implode(DIRECTORY_SEPARATOR, filter_var_array($arrUrl)); |
|
| 247 | 247 | |
| 248 | - extract ( $vars ); |
|
| 249 | - ob_start (); |
|
| 248 | + extract($vars); |
|
| 249 | + ob_start(); |
|
| 250 | 250 | require $filePath; |
| 251 | - $data = ob_get_contents (); |
|
| 252 | - ob_end_clean (); |
|
| 251 | + $data = ob_get_contents(); |
|
| 252 | + ob_end_clean(); |
|
| 253 | 253 | |
| 254 | 254 | return $data; |
| 255 | 255 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | const SEPARETOR = "_"; |
| 24 | 24 | |
| 25 | - protected function init () |
|
| 25 | + protected function init() |
|
| 26 | 26 | { |
| 27 | 27 | } |
| 28 | 28 | |
@@ -31,50 +31,50 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function getParams () |
|
| 34 | + protected function getParams() |
|
| 35 | 35 | { |
| 36 | - if ( ! $this->config or ! $this->isValidFrameworkFiles () ) |
|
| 36 | + if ( ! $this->config or ! $this->isValidFrameworkFiles()) |
|
| 37 | 37 | { |
| 38 | - return array (); |
|
| 38 | + return array(); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - return array ( |
|
| 41 | + return array( |
|
| 42 | 42 | //Driver do banco de dados |
| 43 | - 'driver' => $this->config[ 'adapter' ] , |
|
| 43 | + 'driver' => $this->config['adapter'], |
|
| 44 | 44 | //Nome do banco de dados |
| 45 | - 'database' => $this->config[ 'params' ][ 'dbname' ] , |
|
| 45 | + 'database' => $this->config['params']['dbname'], |
|
| 46 | 46 | //Host do banco |
| 47 | - 'host' => $this->config[ 'params' ][ 'host' ] , |
|
| 47 | + 'host' => $this->config['params']['host'], |
|
| 48 | 48 | //Port do banco |
| 49 | - 'port' => isset( $this->config[ 'params' ][ 'port' ] ) |
|
| 50 | - ? $this->config[ 'params' ][ 'port' ] : '' , |
|
| 49 | + 'port' => isset($this->config['params']['port']) |
|
| 50 | + ? $this->config['params']['port'] : '', |
|
| 51 | 51 | //usuario do banco |
| 52 | - 'username' => $this->config[ 'params' ][ 'username' ] , |
|
| 52 | + 'username' => $this->config['params']['username'], |
|
| 53 | 53 | //senha do banco |
| 54 | - 'password' => $this->config[ 'params' ][ 'password' ] , |
|
| 54 | + 'password' => $this->config['params']['password'], |
|
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - protected function parseFrameworkConfig () |
|
| 58 | + protected function parseFrameworkConfig() |
|
| 59 | 59 | { |
| 60 | - if ( ! $this->isValidFrameworkFiles () ) |
|
| 60 | + if ( ! $this->isValidFrameworkFiles()) |
|
| 61 | 61 | { |
| 62 | 62 | return; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $frameworkIni = $this->getFrameworkIni (); |
|
| 65 | + $frameworkIni = $this->getFrameworkIni(); |
|
| 66 | 66 | |
| 67 | 67 | require_once 'Zend/Config/Ini.php'; |
| 68 | 68 | |
| 69 | 69 | $objConfig = new \Zend_Config_Ini( |
| 70 | - realpath ( $frameworkIni ) , $this->getEnvironment () |
|
| 70 | + realpath($frameworkIni), $this->getEnvironment() |
|
| 71 | 71 | ); |
| 72 | 72 | |
| 73 | - $arrConfig = $objConfig->toArray (); |
|
| 73 | + $arrConfig = $objConfig->toArray(); |
|
| 74 | 74 | |
| 75 | - if ( isset( $arrConfig[ 'resources' ][ 'db' ] ) ) |
|
| 75 | + if (isset($arrConfig['resources']['db'])) |
|
| 76 | 76 | { |
| 77 | - $this->config = $arrConfig[ 'resources' ][ 'db' ]; |
|
| 77 | + $this->config = $arrConfig['resources']['db']; |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @return \Classes\AdapterMakerFile\AbstractAdapter[] |
| 85 | 85 | */ |
| 86 | - public function getMakeFileInstances () |
|
| 86 | + public function getMakeFileInstances() |
|
| 87 | 87 | { |
| 88 | - return array ( |
|
| 89 | - DbTable::getInstance () , |
|
| 90 | - Entity::getInstance () , |
|
| 91 | - Model::getInstance () |
|
| 88 | + return array( |
|
| 89 | + DbTable::getInstance(), |
|
| 90 | + Entity::getInstance(), |
|
| 91 | + Model::getInstance() |
|
| 92 | 92 | ); |
| 93 | 93 | } |
| 94 | 94 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | const SEPARETOR = "\\"; |
| 25 | 25 | |
| 26 | - protected function init () |
|
| 26 | + protected function init() |
|
| 27 | 27 | { |
| 28 | 28 | } |
| 29 | 29 | |
@@ -32,12 +32,12 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return array |
| 34 | 34 | */ |
| 35 | - protected function getParams () |
|
| 35 | + protected function getParams() |
|
| 36 | 36 | { |
| 37 | 37 | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - protected function parseFrameworkConfig () |
|
| 40 | + protected function parseFrameworkConfig() |
|
| 41 | 41 | { |
| 42 | 42 | // TODO: Implement parseFrameworkConfig() method. |
| 43 | 43 | } |
@@ -45,18 +45,18 @@ discard block |
||
| 45 | 45 | /** |
| 46 | 46 | * @inheritdoc |
| 47 | 47 | */ |
| 48 | - protected function getBaseNamespace () |
|
| 48 | + protected function getBaseNamespace() |
|
| 49 | 49 | { |
| 50 | - if ( ! $this->arrConfig[ 'namespace' ] ) |
|
| 50 | + if ( ! $this->arrConfig['namespace']) |
|
| 51 | 51 | { |
| 52 | - return array ( |
|
| 53 | - 'App' , |
|
| 52 | + return array( |
|
| 53 | + 'App', |
|
| 54 | 54 | 'Model' |
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - return array ( |
|
| 59 | - $this->arrConfig[ 'namespace' ] , |
|
| 58 | + return array( |
|
| 59 | + $this->arrConfig['namespace'], |
|
| 60 | 60 | 'Model' |
| 61 | 61 | ); |
| 62 | 62 | } |
@@ -65,11 +65,11 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @return \Classes\AdapterMakerFile\AbstractAdapter[] |
| 67 | 67 | */ |
| 68 | - public function getMakeFileInstances () |
|
| 68 | + public function getMakeFileInstances() |
|
| 69 | 69 | { |
| 70 | - return array ( |
|
| 71 | - Entity::getInstance () , |
|
| 72 | - Model::getInstance () |
|
| 70 | + return array( |
|
| 71 | + Entity::getInstance(), |
|
| 72 | + Model::getInstance() |
|
| 73 | 73 | ); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | const SEPARETOR = "_"; |
| 24 | 24 | |
| 25 | - protected function init () |
|
| 25 | + protected function init() |
|
| 26 | 26 | { |
| 27 | 27 | } |
| 28 | 28 | |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | - protected function getParams () |
|
| 34 | + protected function getParams() |
|
| 35 | 35 | { |
| 36 | 36 | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - protected function parseFrameworkConfig () |
|
| 39 | + protected function parseFrameworkConfig() |
|
| 40 | 40 | { |
| 41 | 41 | // TODO: Implement parseFrameworkConfig() method. |
| 42 | 42 | } |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return \Classes\AdapterMakerFile\AbstractAdapter[] |
| 48 | 48 | */ |
| 49 | - public function getMakeFileInstances () |
|
| 49 | + public function getMakeFileInstances() |
|
| 50 | 50 | { |
| 51 | - return array ( |
|
| 52 | - DbTable::getInstance (), |
|
| 53 | - Entity::getInstance (), |
|
| 54 | - Model::getInstance () |
|
| 51 | + return array( |
|
| 52 | + DbTable::getInstance(), |
|
| 53 | + Entity::getInstance(), |
|
| 54 | + Model::getInstance() |
|
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -19,6 +19,6 @@ |
||
| 19 | 19 | |
| 20 | 20 | public function parseRelation ( \Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable ) |
| 21 | 21 | { |
| 22 | - return array(); |
|
| 22 | + return array(); |
|
| 23 | 23 | } |
| 24 | 24 | } |
@@ -12,9 +12,9 @@ |
||
| 12 | 12 | /** |
| 13 | 13 | * @var void |
| 14 | 14 | */ |
| 15 | - protected $fileTpl = "model.php"; |
|
| 15 | + protected $fileTpl = "model.php"; |
|
| 16 | 16 | |
| 17 | - public function parseRelation ( \Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable ) |
|
| 17 | + public function parseRelation(\Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable) |
|
| 18 | 18 | { |
| 19 | 19 | return array(); |
| 20 | 20 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | protected $fileTpl = "entity.php"; |
| 21 | 21 | protected $overwrite = true; |
| 22 | 22 | |
| 23 | - protected $validFunc = array (); |
|
| 23 | + protected $validFunc = array(); |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @param \Classes\MakerFile $makerFile |
@@ -28,12 +28,12 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return array |
| 30 | 30 | */ |
| 31 | - public function parseRelation ( \Classes\MakerFile $makerFile , \Classes\Db\DbTable $dbTable ) |
|
| 31 | + public function parseRelation(\Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable) |
|
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - return array ( |
|
| 35 | - 'mapParents' => $this->listParents ( $makerFile , $dbTable ) , |
|
| 36 | - 'mapDependents' => $this->listDependence ( $makerFile , $dbTable ) |
|
| 34 | + return array( |
|
| 35 | + 'mapParents' => $this->listParents($makerFile, $dbTable), |
|
| 36 | + 'mapDependents' => $this->listDependence($makerFile, $dbTable) |
|
| 37 | 37 | ); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -43,27 +43,27 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return array |
| 45 | 45 | */ |
| 46 | - private function listParents ( \Classes\MakerFile $makerFile , \Classes\Db\DbTable $dbTable ) |
|
| 46 | + private function listParents(\Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable) |
|
| 47 | 47 | { |
| 48 | 48 | $mapParents = ''; |
| 49 | - $references = array (); |
|
| 50 | - foreach ( $dbTable->getForeingkeys () as $objColumn ) |
|
| 49 | + $references = array(); |
|
| 50 | + foreach ($dbTable->getForeingkeys() as $objColumn) |
|
| 51 | 51 | { |
| 52 | - $constrant = $objColumn->getFks (); |
|
| 53 | - $references[] = sprintf ( |
|
| 54 | - "\$this->hasMany('%s', '%s', '%s')" , |
|
| 55 | - $objColumn->getName () , |
|
| 56 | - $makerFile->getConfig ()->createClassNamespace ( $constrant ) |
|
| 52 | + $constrant = $objColumn->getFks(); |
|
| 53 | + $references[] = sprintf( |
|
| 54 | + "\$this->hasMany('%s', '%s', '%s')", |
|
| 55 | + $objColumn->getName(), |
|
| 56 | + $makerFile->getConfig()->createClassNamespace($constrant) |
|
| 57 | 57 | . Phalcon::SEPARETOR |
| 58 | - . AbstractMaker::getClassName ( $constrant->getTable () ) , |
|
| 59 | - $constrant->getColumn () |
|
| 58 | + . AbstractMaker::getClassName($constrant->getTable()), |
|
| 59 | + $constrant->getColumn() |
|
| 60 | 60 | |
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if ( sizeof ( $references ) > 0 ) |
|
| 64 | + if (sizeof($references) > 0) |
|
| 65 | 65 | { |
| 66 | - $mapParents = join ( ";\n\t\t" , $references ) . ";\n"; |
|
| 66 | + $mapParents = join(";\n\t\t", $references) . ";\n"; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -76,29 +76,29 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return array |
| 78 | 78 | */ |
| 79 | - private function listDependence ( \Classes\MakerFile $makerFile , \Classes\Db\DbTable $dbTable ) |
|
| 79 | + private function listDependence(\Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable) |
|
| 80 | 80 | { |
| 81 | 81 | $mapDependence = ''; |
| 82 | - $references = array (); |
|
| 83 | - foreach ( $dbTable->getDependences () as $objColumn ) |
|
| 82 | + $references = array(); |
|
| 83 | + foreach ($dbTable->getDependences() as $objColumn) |
|
| 84 | 84 | { |
| 85 | - foreach ( $objColumn->getDependences () as $dependence ) |
|
| 85 | + foreach ($objColumn->getDependences() as $dependence) |
|
| 86 | 86 | { |
| 87 | - $references[] = sprintf ( |
|
| 88 | - "\$this->belongsTo('%s', '%s', '%s')" , |
|
| 89 | - $objColumn->getName () , |
|
| 90 | - $makerFile->getConfig ()->createClassNamespace ( $dependence ) |
|
| 87 | + $references[] = sprintf( |
|
| 88 | + "\$this->belongsTo('%s', '%s', '%s')", |
|
| 89 | + $objColumn->getName(), |
|
| 90 | + $makerFile->getConfig()->createClassNamespace($dependence) |
|
| 91 | 91 | . Phalcon::SEPARETOR |
| 92 | - . AbstractMaker::getClassName ( $dependence->getTable () ) , |
|
| 93 | - $dependence->getColumn () |
|
| 92 | + . AbstractMaker::getClassName($dependence->getTable()), |
|
| 93 | + $dependence->getColumn() |
|
| 94 | 94 | ); |
| 95 | 95 | |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if ( sizeof ( $references ) > 0 ) |
|
| 99 | + if (sizeof($references) > 0) |
|
| 100 | 100 | { |
| 101 | - $mapDependence = join ( ";\n\t\t" , $references ) . ";"; |
|
| 101 | + $mapDependence = join(";\n\t\t", $references) . ";"; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | return $mapDependence; |