Skip to content

Commit

Permalink
Merge pull request #3 from pedro151/v1.3.x
Browse files Browse the repository at this point in the history
V1.3.x
  • Loading branch information
pedro151 committed Jun 11, 2016
2 parents 0dddb16 + 97fe9ae commit eff0673
Show file tree
Hide file tree
Showing 21 changed files with 485 additions and 104 deletions.
Binary file modified bin/orm-generator.phar
Binary file not shown.
10 changes: 9 additions & 1 deletion build/Classes/AdapterConfig/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ public function createClassNamespace ( $table )
$arrNames[] = AbstractMaker::getClassName ( $this->arrConfig[ 'driver' ] );
}

if ( isset( $this->arrConfig[ 'folder-name' ] )
&& $this->arrConfig[ 'folder-name' ]
)
{
$arrNames[] = AbstractMaker::getClassName ( $this->arrConfig[ 'folder-name' ] );
}

if ( $table->hasSchema () )
{
$arrNames[] = AbstractMaker::getClassName ( $table->getSchema () );
Expand Down Expand Up @@ -362,7 +369,8 @@ public function __get ( $str )
'link' ,
'last_modify' ,
'path' ,
'folder-database'
'folder-database',
'folder-name'
);

if ( in_array ( $str , $arr ) )
Expand Down
27 changes: 17 additions & 10 deletions build/Classes/AdapterMakerFile/ZendFrameworkOne/DbTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public function parseRelation ( \Classes\MakerFile $makerFile, \Classes\Db\DbTab
foreach ( $dbTable->getForeingkeys () as $objColumn )
{
$constrant = $objColumn->getFks ();

$arrClass = array (
$makerFile->getConfig ()->createClassNamespace ( $constrant ),
'DbTable',
AbstractMaker::getClassName ( $constrant->getTable () )
);
$class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) );

$references[] = sprintf (
"
'%s' => array (
Expand All @@ -46,11 +54,7 @@ public function parseRelation ( \Classes\MakerFile $makerFile, \Classes\Db\DbTab
)",
AbstractMaker::getClassName ( $constrant->getNameConstrant () ),
$objColumn->getName (),
$makerFile->getConfig ()->createClassNamespace ( $constrant )
. ZendFrameworkOne::SEPARETOR
. 'DbTable'
. ZendFrameworkOne::SEPARETOR
. AbstractMaker::getClassName ( $constrant->getTable () ),
$class,
$constrant->getColumn ()

);
Expand All @@ -66,11 +70,14 @@ public function parseRelation ( \Classes\MakerFile $makerFile, \Classes\Db\DbTab
{
foreach ( $objColumn->getDependences () as $dependence )
{
$dependents[] = $makerFile->getConfig ()->createClassNamespace ( $dependence )
. ZendFrameworkOne::SEPARETOR
. 'DbTable'
. ZendFrameworkOne::SEPARETOR
. AbstractMaker::getClassName ( $dependence->getTable () );
$arrClass = array (
$makerFile->getConfig ()->createClassNamespace ( $dependence ),
'DbTable',
AbstractMaker::getClassName ( $dependence->getTable () )
);
$class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) );

$dependents[] = $class;
}
}

Expand Down
22 changes: 14 additions & 8 deletions build/Classes/AdapterMakerFile/ZendFrameworkOne/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ private function listParents ( \Classes\MakerFile $makerFile , \Classes\Db\DbTab
. ZendFrameworkOne::SEPARETOR
. $objColumn->getName ();

$arrClass = array (
$makerFile->getConfig ()->createClassNamespace ( $constrant ),
AbstractMaker::getClassName ( $constrant->getTable () )
);
$class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) );

$parents[] = array (
'class' => $makerFile->getConfig ()
->createClassNamespace ( $constrant )
. ZendFrameworkOne::SEPARETOR
. AbstractMaker::getClassName ( $constrant->getTable () ) ,
'class' => $class ,
'function' => AbstractMaker::getClassName ( $name ) ,
'table' => $constrant->getTable () ,
'column' => $objColumn->getName () ,
Expand Down Expand Up @@ -99,12 +102,15 @@ private function listDependence ( \Classes\MakerFile $makerFile , \Classes\Db\Db

if ( ! key_exists ( $name , $this->validFunc ) )
{
$arrClass = array (
$makerFile->getConfig ()->createClassNamespace ( $dependence ),
AbstractMaker::getClassName ( $dependence->getTable () )
);
$class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) );

$this->validFunc[ $name ] = true;
$depends[] = array (
'class' => $makerFile->getConfig ()
->createClassNamespace ( $dependence )
. ZendFrameworkOne::SEPARETOR
. AbstractMaker::getClassName ( $dependence->getTable () ) ,
'class' => $class,
'function' => AbstractMaker::getClassName ( $name ) ,
'table' => $dependence->getTable () ,
'column' => $dependence->getColumn () ,
Expand Down
4 changes: 3 additions & 1 deletion build/Classes/AdaptersDriver/AbsractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ private function populateForeignAndPrimaryKeys ( $constrant , $table_name , $sch
'constrant' => $constrant[ 'constraint_name' ] ,
'schema' => $constrant[ 'foreign_schema' ] ,
'table' => $constrant[ 'foreign_table' ] ,
'column' => $constrant[ 'foreign_column' ]
'column' => $constrant[ 'foreign_column' ],
'database' => $this->database
)
);

Expand Down Expand Up @@ -155,6 +156,7 @@ private function populateDependece ( $constrant , $table_name , $schema = 0 )
$constrant[ 'constraint_name' ] ,
$constrant[ 'table_name' ] ,
$constrant[ 'column_name' ] ,
$this->database,
$constrant[ 'table_schema' ]
);
}
Expand Down
3 changes: 2 additions & 1 deletion build/Classes/AdaptersDriver/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public function getListConstrant ()
0 AS table_schema,
k.table_name,
k.column_name,
k.REFERENCED_TABLE_SCHEMA AS foreign_schema,
-- k.REFERENCED_TABLE_SCHEMA AS foreign_schema,
0 AS foreign_schema,
k.REFERENCED_TABLE_NAME AS foreign_table,
k.REFERENCED_COLUMN_NAME AS foreign_column
FROM information_schema.TABLE_CONSTRAINTS as i
Expand Down
66 changes: 32 additions & 34 deletions build/Classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,20 @@ class Config
*/
private $adapterDriver;

public function __construct ( $argv , $basePath )
private $frameworkList = array (
'zf1', 'phalcon'
);

public function __construct ( $argv, $basePath )
{
if ( array_key_exists ( 'help' , $argv ) )
{
if ( array_key_exists ( 'help', $argv ) ) {
die ( $this->getUsage () );
}
if ( array_key_exists ( 'status' , $argv ) )
{
if ( array_key_exists ( 'status', $argv ) ) {
$argv[ 'status' ] = true;
}

$this->argv = $this->parseConfig ( $basePath , $argv );
$this->argv = $this->parseConfig ( $basePath, $argv );
}

/**
Expand All @@ -85,7 +87,7 @@ public function __construct ( $argv , $basePath )
*/
public function getUsage ()
{
$version = $this->getVersion();
$version = $this->getVersion ();

return <<<EOF
parameters:
Expand Down Expand Up @@ -119,26 +121,30 @@ public function getVersion ()
* Analisa e estrutura a Configuracao do generate
*
* @param string $basePath
* @param array $argv
* @param array $argv
*
* @return array
* @throws \Exception
*/
private function parseConfig ( $basePath , $argv )
private function parseConfig ( $basePath, $argv )
{
$this->_basePath = dirname ( $basePath );

$configIni = isset( $argv[ 'config-ini' ] ) ? $argv[ 'config-ini' ]
: $this->_basePath . $this->configIniDefault;

$configTemp = $this->loadIniFile ( realpath ( $configIni ) );
$configCurrent = self::parseConfigEnv ( $configTemp , $argv );
$configTemp = $this->loadIniFile ( realpath ( $configIni ) );
$configCurrent = self::parseConfigEnv ( $configTemp, $argv );

if ( ! isset( $configCurrent[ 'framework' ] ) )
{
if ( !isset( $configCurrent[ 'framework' ] ) ) {
throw new \Exception( "configure which framework you want to use! \n" );
}

if ( !in_array ( $configCurrent[ 'framework' ], $this->frameworkList ) ) {
$frameworks = implode("\n\t", $this->frameworkList);
throw new \Exception( "list of frameworks: \n".$frameworks."\n" );
}

return $argv + array_filter ( $configCurrent );
}

Expand All @@ -149,16 +155,15 @@ private function parseConfig ( $basePath , $argv )
*
* @return string
*/
private static function parseConfigEnv ( $configTemp , $argv )
private static function parseConfigEnv ( $configTemp, $argv )
{
$thisSection = isset( $configTemp[ key ( $configTemp ) ][ 'config-env' ] ) ?
$configTemp[ key ( $configTemp ) ][ 'config-env' ] : null;

$thisSection = isset( $argv[ 'config-env' ] ) ? $argv[ 'config-env' ]
: $thisSection;

if ( isset( $configTemp[ $thisSection ][ 'extends' ] ) )
{
if ( isset( $configTemp[ $thisSection ][ 'extends' ] ) ) {
#faz marge da config principal com a config extendida
return $configTemp[ $thisSection ]
+ $configTemp[ $configTemp[ $thisSection ][ 'extends' ] ];
Expand All @@ -180,26 +185,23 @@ private static function parseConfigEnv ( $configTemp , $argv )
*/
protected function loadIniFile ( $filename )
{
if ( ! is_file ( $filename ) )
{
if ( !is_file ( $filename ) ) {
throw new \Exception( "configuration file does not exist! \n" );
}

$loaded = parse_ini_file ( $filename , true );
$loaded = parse_ini_file ( $filename, true );
$iniArray = array ();
foreach ( $loaded as $key => $data )
{
$pieces = explode ( $this->sectionSeparator , $key );
foreach ( $loaded as $key => $data ) {
$pieces = explode ( $this->sectionSeparator, $key );
$thisSection = trim ( $pieces[ 0 ] );
switch ( count ( $pieces ) )
{
switch ( count ( $pieces ) ) {
case 1:
$iniArray[ $thisSection ] = $data;
break;

case 2:
$extendedSection = trim ( $pieces[ 1 ] );
$iniArray[ $thisSection ] = array_merge ( array ( 'extends' => $extendedSection ) , $data );
$extendedSection = trim ( $pieces[ 1 ] );
$iniArray[ $thisSection ] = array_merge ( array ( 'extends' => $extendedSection ), $data );
break;

default:
Expand All @@ -218,8 +220,7 @@ protected function loadIniFile ( $filename )
*/
private function factoryConfig ()
{
switch ( strtolower ( $this->argv[ 'framework' ] ) )
{
switch ( strtolower ( $this->argv[ 'framework' ] ) ) {
case 'zf1':
return new ZendFrameworkOne( $this->argv );
case 'phalcon':
Expand All @@ -237,8 +238,7 @@ private function factoryConfig ()
*/
private function factoryDriver ()
{
switch ( $this->argv[ 'driver' ] )
{
switch ( $this->argv[ 'driver' ] ) {
case 'pgsql':
case 'pdo_pgsql':
return new Pgsql( $this->getAdapterConfig () );
Expand All @@ -259,8 +259,7 @@ private function factoryDriver ()
*/
public function getAdapterConfig ()
{
if ( ! $this->adapterConfig instanceof AbstractAdapter )
{
if ( !$this->adapterConfig instanceof AbstractAdapter ) {
$this->adapterConfig = $this->factoryConfig ();
}

Expand All @@ -272,8 +271,7 @@ public function getAdapterConfig ()
*/
public function getAdapterDriver ()
{
if ( ! $this->adapterDriver )
{
if ( !$this->adapterDriver ) {
$this->adapterDriver = $this->factoryDriver ();
}

Expand Down
5 changes: 3 additions & 2 deletions build/Classes/Db/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,16 @@ public function addDependece ( Constrant $dependece )
*
* @return $this
*/
public function createDependece ( $constraint_name , $table_name , $column_name , $schema = null )
public function createDependece ( $constraint_name , $table_name , $column_name ,$database, $schema = null )
{
$objConstrantDependence = Constrant::getInstance ()
->populate (
array (
'constrant' => $constraint_name ,
'schema' => $schema ,
'table' => $table_name ,
'column' => $column_name
'column' => $column_name,
'database' => $database
)
);

Expand Down
5 changes: 4 additions & 1 deletion build/Classes/Db/Constrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@ public function populate ( $array )
$this->schema = $array[ 'schema' ];
}

$this->database = $array[ 'database' ];
$this->constrant = $array[ 'constrant' ];
$this->table = $array[ 'table' ];
$this->column = $array[ 'column' ];

return $this;
}

public function getDatabase (){ }
public function getDatabase (){
return $this->database;
}

/**
* @return string
Expand Down
11 changes: 9 additions & 2 deletions build/Classes/MakerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public function parseLocation ( $basePath )
$classDriver = explode ( '\\' , get_class ( $this->driver ) );
$driverBase = end ( $classDriver );
}
$folderName = '';
if ( $this->config->{"folder-name"} )
{
$folderName = $this->getClassName ( trim ( $this->config->{"folder-name"} ) );
}

if ( $this->config->hasSchemas () )
{
Expand All @@ -72,8 +77,9 @@ public function parseLocation ( $basePath )
foreach ( $schemas as $schema )
{
$arrUrl = array (
$this->baseLocation ,
$driverBase ,
$this->baseLocation,
$driverBase,
$folderName,
$this->getClassName ( $schema )
);

Expand All @@ -88,6 +94,7 @@ public function parseLocation ( $basePath )
DIRECTORY_SEPARATOR , array_filter ( array (
$this->baseLocation ,
$driverBase ,
$folderName ,
$this->getClassName ( $this->getConfig ()->getDatabase () )
)
)
Expand Down
2 changes: 2 additions & 0 deletions build/Classes/templates/file_configs/ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
path = ""
;folder with the database driver name
folder-database = 0
;folder with the name
folder-name=''
;.ini file the framework configuration
framework-ini = ""
;the path to the directory of the framework library
Expand Down

0 comments on commit eff0673

Please sign in to comment.