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 $parentClass = "EntityAbstract"; |
21
|
|
|
protected $parentFileTpl = "entity_abstract.php"; |
22
|
|
|
protected $fileTpl = "entity.php"; |
23
|
|
|
protected $overwrite = true; |
24
|
|
|
|
25
|
|
|
protected $validFunc = array (); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param \Classes\MakerFile $makerFile |
29
|
|
|
* @param \Classes\Db\DbTable $dbTable |
30
|
|
|
* |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
public function parseRelation ( \Classes\MakerFile $makerFile , \Classes\Db\DbTable $dbTable ) |
34
|
|
|
{ |
35
|
|
|
return array ( |
36
|
|
|
'parents' => $this->listParents ( $makerFile , $dbTable ) , |
37
|
|
|
'depends' => $this->listDependence ( $makerFile , $dbTable ) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param \Classes\MakerFile $makerFile |
43
|
|
|
* @param \Classes\Db\DbTable $dbTable |
44
|
|
|
* |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
private function listParents ( \Classes\MakerFile $makerFile , \Classes\Db\DbTable $dbTable ) |
48
|
|
|
{ |
49
|
|
|
$parents = array (); |
50
|
|
|
foreach ( $dbTable->getForeingkeys () as $objColumn ) |
51
|
|
|
{ |
52
|
|
|
$constrant = $objColumn->getFks (); |
53
|
|
|
$name = |
54
|
|
|
'Parent' |
55
|
|
|
. ZendFrameworkOne::SEPARETOR |
56
|
|
|
. AbstractMaker::getClassName ( $constrant->getTable () ) |
57
|
|
|
. ZendFrameworkOne::SEPARETOR |
58
|
|
|
. 'By' |
59
|
|
|
. ZendFrameworkOne::SEPARETOR |
60
|
|
|
. $objColumn->getName (); |
61
|
|
|
|
62
|
|
|
$parents[] = array ( |
63
|
|
|
'class' => $makerFile->getConfig () |
64
|
|
|
->createClassNamespace ( $constrant ) |
65
|
|
|
. ZendFrameworkOne::SEPARETOR |
66
|
|
|
. AbstractMaker::getClassName ( $constrant->getTable () ) , |
67
|
|
|
'function' => AbstractMaker::getClassName ( $name ) , |
68
|
|
|
'table' => $constrant->getTable () , |
69
|
|
|
'column' => $objColumn->getName () , |
70
|
|
|
'name' => $constrant->getNameConstrant () , |
71
|
|
|
); |
72
|
|
|
unset( $name ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $parents; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param \Classes\MakerFile $makerFile |
80
|
|
|
* @param \Classes\Db\DbTable $dbTable |
81
|
|
|
* |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
private function listDependence ( \Classes\MakerFile $makerFile , \Classes\Db\DbTable $dbTable ) |
85
|
|
|
{ |
86
|
|
|
$depends = array (); |
87
|
|
|
foreach ( $dbTable->getDependences () as $objColumn ) |
88
|
|
|
{ |
89
|
|
|
foreach ( $objColumn->getDependences () as $dependence ) |
90
|
|
|
{ |
91
|
|
|
$name = |
92
|
|
|
'Depend' |
93
|
|
|
. ZendFrameworkOne::SEPARETOR |
94
|
|
|
. AbstractMaker::getClassName ( $dependence->getTable () ) |
95
|
|
|
. ZendFrameworkOne::SEPARETOR |
96
|
|
|
. 'By' |
97
|
|
|
. ZendFrameworkOne::SEPARETOR |
98
|
|
|
. $objColumn->getName (); |
99
|
|
|
|
100
|
|
|
if ( ! key_exists ( $name , $this->validFunc ) ) |
101
|
|
|
{ |
102
|
|
|
$this->validFunc[ $name ] = true; |
103
|
|
|
$depends[] = array ( |
104
|
|
|
'class' => $makerFile->getConfig () |
105
|
|
|
->createClassNamespace ( $dependence ) |
106
|
|
|
. ZendFrameworkOne::SEPARETOR |
107
|
|
|
. AbstractMaker::getClassName ( $dependence->getTable () ) , |
108
|
|
|
'function' => AbstractMaker::getClassName ( $name ) , |
109
|
|
|
'table' => $dependence->getTable () , |
110
|
|
|
'column' => $dependence->getColumn () , |
111
|
|
|
'name' => $dependence->getNameConstrant () |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
unset( $name ); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return $depends; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|