1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Classes\AdapterMakerFile\ZendFrameworkOne; |
4
|
|
|
|
5
|
|
|
use Classes\AdapterMakerFile\AbstractAdapter; |
6
|
|
|
use Classes\AdapterConfig\ZendFrameworkOne; |
7
|
|
|
use Classes\Maker\AbstractMaker; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @author Pedro Alarcao <[email protected]> |
11
|
|
|
* @link https://github.com/pedro151/orm-generator |
12
|
|
|
*/ |
13
|
|
|
class Entity extends AbstractAdapter |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var void |
18
|
|
|
*/ |
19
|
|
|
public $pastName = 'Entity'; |
20
|
|
|
protected $fileTpl = "entity.php"; |
21
|
|
|
protected $fileFixedData = array ( |
22
|
|
|
'parentclass' => array ( |
23
|
|
|
'name' => "EntityAbstract" , |
24
|
|
|
'tpl' => "entity_abstract.php" |
25
|
|
|
) , |
26
|
|
|
'exception' => array ( |
27
|
|
|
'name' => "EntityException" , |
28
|
|
|
'tpl' => "entity_exception.php" |
29
|
|
|
) |
30
|
|
|
); |
31
|
|
|
protected $overwrite = true; |
32
|
|
|
|
33
|
|
|
protected $validFunc = array (); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param \Classes\MakerFile $makerFile |
37
|
|
|
* @param \Classes\Db\DbTable $dbTable |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
public function parseRelation ( \Classes\MakerFile $makerFile , \Classes\Db\DbTable $dbTable ) |
42
|
|
|
{ |
43
|
|
|
return array ( |
44
|
|
|
'parents' => $this->listParents ( $makerFile , $dbTable ) , |
45
|
|
|
'depends' => $this->listDependence ( $makerFile , $dbTable ) |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param \Classes\MakerFile $makerFile |
51
|
|
|
* @param \Classes\Db\DbTable $dbTable |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
private function listParents ( \Classes\MakerFile $makerFile , \Classes\Db\DbTable $dbTable ) |
56
|
|
|
{ |
57
|
|
|
$parents = array (); |
58
|
|
|
foreach ( $dbTable->getForeingkeys () as $objColumn ) |
59
|
|
|
{ |
60
|
|
|
$constrant = $objColumn->getFks (); |
61
|
|
|
$name = |
62
|
|
|
'Parent' |
63
|
|
|
. ZendFrameworkOne::SEPARETOR |
64
|
|
|
. AbstractMaker::getClassName ( $constrant->getTable () ) |
65
|
|
|
. ZendFrameworkOne::SEPARETOR |
66
|
|
|
. 'By' |
67
|
|
|
. ZendFrameworkOne::SEPARETOR |
68
|
|
|
. $objColumn->getName (); |
69
|
|
|
|
70
|
|
|
$variable = $constrant->getNameConstrant () . ZendFrameworkOne::SEPARETOR . $objColumn->getName (); |
71
|
|
|
|
72
|
|
|
$arrClass = array ( |
73
|
|
|
$makerFile->getConfig ()->createClassNamespace ( $constrant ), |
74
|
|
|
AbstractMaker::getClassName ( $constrant->getTable () ) |
75
|
|
|
); |
76
|
|
|
$class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) ); |
77
|
|
|
|
78
|
|
|
$parents[] = array ( |
79
|
|
|
'class' => $class , |
80
|
|
|
'function' => AbstractMaker::getClassName ( $name ) , |
81
|
|
|
'table' => $constrant->getTable () , |
82
|
|
|
'column' => $constrant->getColumn() , |
83
|
|
|
'name' => $constrant->getNameConstrant() , |
84
|
|
|
'variable' => $variable |
85
|
|
|
|
86
|
|
|
); |
87
|
|
|
unset( $name ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $parents; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param \Classes\MakerFile $makerFile |
95
|
|
|
* @param \Classes\Db\DbTable $dbTable |
96
|
|
|
* |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
private function listDependence ( \Classes\MakerFile $makerFile , \Classes\Db\DbTable $dbTable ) |
100
|
|
|
{ |
101
|
|
|
$depends = array (); |
102
|
|
|
foreach ( $dbTable->getDependences () as $objColumn ) |
103
|
|
|
{ |
104
|
|
|
foreach ( $objColumn->getDependences () as $dependence ) |
105
|
|
|
{ |
106
|
|
|
$name = |
107
|
|
|
'Depend' |
108
|
|
|
. ZendFrameworkOne::SEPARETOR |
109
|
|
|
. AbstractMaker::getClassName ( $dependence->getTable () ) |
110
|
|
|
. ZendFrameworkOne::SEPARETOR |
111
|
|
|
. 'By' |
112
|
|
|
. ZendFrameworkOne::SEPARETOR |
113
|
|
|
. $objColumn->getName (); |
114
|
|
|
|
115
|
|
|
if ( ! key_exists ( $name , $this->validFunc ) ) |
116
|
|
|
{ |
117
|
|
|
$variable = $dependence->getNameConstrant () . ZendFrameworkOne::SEPARETOR . $objColumn->getName (); |
118
|
|
|
|
119
|
|
|
$arrClass = array ( |
120
|
|
|
$makerFile->getConfig ()->createClassNamespace ( $dependence ), |
121
|
|
|
AbstractMaker::getClassName ( $dependence->getTable () ) |
122
|
|
|
); |
123
|
|
|
$class = implode ( ZendFrameworkOne::SEPARETOR , array_filter ( $arrClass ) ); |
124
|
|
|
|
125
|
|
|
$this->validFunc[ $name ] = true; |
126
|
|
|
$depends[] = array ( |
127
|
|
|
'class' => $class, |
128
|
|
|
'function' => AbstractMaker::getClassName ( $name ) , |
129
|
|
|
'table' => $dependence->getTable () , |
130
|
|
|
'column' => $dependence->getColumn () , |
131
|
|
|
'name' => $dependence->getNameConstrant (), |
132
|
|
|
'variable' => $variable |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
unset( $name ); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return $depends; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
|