|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ubiquity\utils\yuml\traits; |
|
4
|
|
|
|
|
5
|
|
|
use Ubiquity\orm\OrmUtils; |
|
6
|
|
|
use Ubiquity\utils\yuml\ClassToYuml; |
|
7
|
|
|
use Ubiquity\utils\yuml\Yuml; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Ubiquity\utils\yuml\traits$ClassToYumlRelationsTrait |
|
11
|
|
|
* This class is part of Ubiquity |
|
12
|
|
|
* |
|
13
|
|
|
* @author jcheron <[email protected]> |
|
14
|
|
|
* @version 1.0.3 |
|
15
|
|
|
* |
|
16
|
|
|
*/ |
|
17
|
|
|
trait ClassToYumlRelationsTrait { |
|
18
|
|
|
protected $oneToManys = [ ]; |
|
19
|
|
|
protected $manyToOne = [ ]; |
|
20
|
|
|
protected $manyToManys = [ ]; |
|
21
|
|
|
protected $extManyToManys = [ ]; |
|
22
|
|
|
|
|
23
|
2 |
|
protected function loadOneToManys() { |
|
24
|
2 |
|
$oneToManys = OrmUtils::getAnnotationInfo ( $this->class, "#oneToMany" ); |
|
25
|
2 |
|
if ($oneToManys) { |
|
26
|
2 |
|
foreach ( $oneToManys as $member => $array ) { |
|
27
|
2 |
|
$this->oneToManys [$member] = $array ["className"]; |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
2 |
|
} |
|
31
|
|
|
|
|
32
|
2 |
|
public function loadManyToManys() { |
|
33
|
2 |
|
$manyToManys = OrmUtils::getAnnotationInfo ( $this->class, "#manyToMany" ); |
|
34
|
2 |
|
if ($manyToManys) { |
|
35
|
2 |
|
foreach ( $manyToManys as $member => $array ) { |
|
36
|
2 |
|
if (isset ( $array ["targetEntity"] )) { |
|
37
|
2 |
|
$this->manyToManys [$member] = $array ["targetEntity"]; |
|
38
|
2 |
|
$this->extManyToManys [$array ["targetEntity"]] = $this->class; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
2 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function loadManyToOne() { |
|
45
|
|
|
$manyToOne = OrmUtils::getAnnotationInfo ( $this->class, "#manyToOne" ); |
|
46
|
|
|
if ($manyToOne) { |
|
47
|
|
|
foreach ( $manyToOne as $member ) { |
|
48
|
|
|
$joinColumn = OrmUtils::getAnnotationInfoMember ( $this->class, "#joinColumn", $member ); |
|
49
|
|
|
if ($joinColumn && isset ( $joinColumn ["className"] )) { |
|
50
|
|
|
$this->manyToOne [$member] = $joinColumn ["className"]; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
2 |
|
protected function getShortClassName($class) { |
|
57
|
2 |
|
$reflect = new \ReflectionClass ( $class ); |
|
58
|
2 |
|
return $reflect->getShortName (); |
|
59
|
2 |
|
} |
|
60
|
2 |
|
|
|
61
|
|
|
protected function _getYumlRelationsType($relations, $branche) { |
|
62
|
2 |
|
$myClass = $this->getShortClassName ( $this->class ); |
|
63
|
|
|
$yumlRelations = [ ]; |
|
64
|
|
|
foreach ( $relations as $model ) { |
|
65
|
|
|
$yumlRelations [] = Yuml::setClassContent ( $myClass ) . $branche . new ClassToYuml ( $model, $this->displayAssociationClassProperties, false ); |
|
66
|
|
|
} |
|
67
|
|
|
return $yumlRelations; |
|
68
|
|
|
} |
|
69
|
2 |
|
|
|
70
|
2 |
|
protected function _getYumlManyToOne() { |
|
71
|
|
|
return $this->_getYumlRelationsType ( $this->manyToOne, "0..*-1" ); |
|
72
|
|
|
} |
|
73
|
2 |
|
|
|
74
|
2 |
|
protected function _getYumlOneToMany() { |
|
75
|
|
|
return $this->_getYumlRelationsType ( $this->oneToManys, "1-0..*" ); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function _getYumlManyToMany() { |
|
79
|
|
|
return $this->_getYumlRelationsType ( $this->manyToManys, "0..*-0..*" ); |
|
80
|
|
|
} |
|
81
|
2 |
|
|
|
82
|
2 |
|
/** |
|
83
|
|
|
* |
|
84
|
|
|
* @return array |
|
85
|
2 |
|
*/ |
|
86
|
2 |
|
public function getExtManyToManys() { |
|
87
|
2 |
|
return $this->extManyToManys; |
|
88
|
2 |
|
} |
|
89
|
|
|
|
|
90
|
2 |
|
public function removeManyToManyExt($targetClass) { |
|
91
|
|
|
$member = array_search ( $targetClass, $this->manyToManys ); |
|
92
|
|
|
if ($member !== false) { |
|
93
|
|
|
unset ( $this->manyToManys [$member] ); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
|