|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Classes\AdapterMakerFile\Phalcon; |
|
4
|
|
|
|
|
5
|
|
|
use Classes\AdapterConfig\Phalcon; |
|
6
|
|
|
use Classes\AdapterMakerFile\AbstractAdapter; |
|
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
|
|
|
public $pastName = 'Entity'; |
|
17
|
|
|
protected $fileTpl = "entity.php"; |
|
18
|
|
|
protected $fileFixedData = array ( |
|
19
|
|
|
'parentclass' => array ( |
|
20
|
|
|
'name' => "AbstractEntity" , |
|
21
|
|
|
'tpl' => "entity_abstract.php" |
|
22
|
|
|
) |
|
23
|
|
|
); |
|
24
|
|
|
|
|
25
|
|
|
protected $overwrite = true; |
|
26
|
|
|
|
|
27
|
|
|
protected $validFunc = array (); |
|
28
|
|
|
|
|
29
|
|
|
private $intersectDependence = false; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param \Classes\MakerFile $makerFile |
|
33
|
|
|
* @param \Classes\Db\DbTable $dbTable |
|
34
|
|
|
* |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
public function parseRelation ( \Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable ) |
|
38
|
|
|
{ |
|
39
|
|
|
return array ( |
|
40
|
|
|
'mapParents' => $this->listParents ( $makerFile, $dbTable ), |
|
41
|
|
|
'mapDependents' => $this->listDependence ( $makerFile, $dbTable ) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param \Classes\MakerFile $makerFile |
|
47
|
|
|
* @param \Classes\Db\DbTable $dbTable |
|
48
|
|
|
* |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
|
View Code Duplication |
private function listParents ( \Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable ) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$mapParents = ''; |
|
54
|
|
|
$references = array (); |
|
55
|
|
|
foreach ( $dbTable->getForeingkeys () as $objColumn ) { |
|
56
|
|
|
$constrant = $objColumn->getFks (); |
|
57
|
|
|
$references[] = sprintf ( |
|
58
|
|
|
'$this->belongsTo(\'%s\', \'%s\', \'%s\', array(\'alias\' => \'%s\'))', |
|
59
|
|
|
$objColumn->getName (), |
|
60
|
|
|
$makerFile->getConfig () |
|
61
|
|
|
->createClassNamespace ( $constrant ) . Phalcon::SEPARETOR . AbstractMaker::getClassName ( |
|
62
|
|
|
$constrant->getTable () |
|
63
|
|
|
), |
|
64
|
|
|
$constrant->getColumn (), |
|
65
|
|
|
AbstractMaker::getClassName ( $constrant->getTable () ) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ( sizeof ( $references ) > 0 ) { |
|
70
|
|
|
$mapParents = join ( ";\n\t\t", $references ) . ";\n"; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
return $mapParents; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param \Classes\MakerFile $makerFile |
|
79
|
|
|
* @param \Classes\Db\DbTable $dbTable |
|
80
|
|
|
* |
|
81
|
|
|
* @return array |
|
82
|
|
|
*/ |
|
83
|
|
View Code Duplication |
private function listDependence ( \Classes\MakerFile $makerFile, \Classes\Db\DbTable $dbTable ) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$mapDependence = ''; |
|
86
|
|
|
$references = array (); |
|
87
|
|
|
foreach ( $dbTable->getDependences () as $objColumn ) { |
|
88
|
|
|
foreach ( $objColumn->getDependences () as $dependence ) { |
|
89
|
|
|
$references[] = sprintf ( |
|
90
|
|
|
'$this->hasMany(\'%s\', \'%s\', \'%s\', array(\'alias\' => \'%s\'))', |
|
91
|
|
|
$objColumn->getName (), |
|
92
|
|
|
$makerFile->getConfig () |
|
93
|
|
|
->createClassNamespace ( $dependence ) |
|
94
|
|
|
. Phalcon::SEPARETOR |
|
95
|
|
|
. AbstractMaker::getClassName ( $dependence->getTable () ), |
|
96
|
|
|
$dependence->getColumn (), |
|
97
|
|
|
AbstractMaker::getClassName ( $dependence->getTable () ) |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
if ( sizeof ( $references ) > 0 ) { |
|
104
|
|
|
$mapDependence = join ( ";\n\t\t", $references ) . ";"; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
return $mapDependence; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.