1
|
|
|
<?php |
2
|
|
|
namespace micro\annotations; |
3
|
|
|
|
4
|
|
|
use micro\orm\Reflexion; |
5
|
|
|
use micro\orm\OrmUtils; |
6
|
|
|
/** |
7
|
|
|
* Annotation ManyToManyParser |
8
|
|
|
* @author jc |
9
|
|
|
* @version 1.0.0.1 |
10
|
|
|
* @package annotations |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
class ManyToManyParser{ |
14
|
|
|
private $member; |
15
|
|
|
private $joinTable; |
16
|
|
|
private $myFkField; |
17
|
|
|
private $fkField; |
18
|
|
|
private $targetEntity; |
19
|
|
|
private $targetEntityClass; |
20
|
|
|
private $targetEntityTable; |
21
|
|
|
private $myPk; |
22
|
|
|
private $inversedBy; |
23
|
|
|
private $pk; |
24
|
|
|
private $instance; |
25
|
|
|
public function __construct($instance,$member){ |
26
|
|
|
$this->instance=$instance; |
27
|
|
|
$this->member=$member; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function init(){ |
31
|
|
|
$member=$this->member; |
32
|
|
|
$instance=$this->instance; |
33
|
|
|
$class=get_class($instance); |
34
|
|
|
$annot=Reflexion::getAnnotationMember($class, $member, "ManyToMany"); |
35
|
|
|
if($annot!==false){ |
36
|
|
|
$this->targetEntity=$annot->targetEntity; |
37
|
|
|
$this->inversedBy=strtolower($this->targetEntity)."s"; |
38
|
|
|
if(!is_null($annot->inversedBy)) |
39
|
|
|
$this->inversedBy=$annot->inversedBy; |
40
|
|
|
$this->targetEntityClass=get_class(new $this->targetEntity()); |
41
|
|
|
|
42
|
|
|
$annotJoinTable=Reflexion::getAnnotationMember($class, $member, "JoinTable"); |
43
|
|
|
$this->joinTable=$annotJoinTable->name; |
44
|
|
|
$joinColumnsAnnot=$annotJoinTable->joinColumns; |
45
|
|
|
$this->myFkField="id".OrmUtils::getTableName($class); |
46
|
|
|
$this->myPk=OrmUtils::getFirstKey($class); |
47
|
|
|
if(!is_null($joinColumnsAnnot)){ |
48
|
|
|
$this->myFkField=$joinColumnsAnnot->name; |
49
|
|
|
$this->myPk=$joinColumnsAnnot->referencedColumnName; |
50
|
|
|
} |
51
|
|
|
$this->targetEntityTable=OrmUtils::getTableName($this->targetEntity); |
52
|
|
|
$this->fkField="id".ucfirst($this->targetEntityTable); |
53
|
|
|
$this->pk=OrmUtils::getFirstKey($this->targetEntityClass); |
54
|
|
|
$inverseJoinColumnsAnnot=$annotJoinTable->inverseJoinColumns; |
55
|
|
|
if(!is_null($inverseJoinColumnsAnnot)){ |
56
|
|
|
$this->fkField=$inverseJoinColumnsAnnot->name; |
57
|
|
|
$this->pk=$inverseJoinColumnsAnnot->referencedColumnName; |
58
|
|
|
} |
59
|
|
|
return true; |
60
|
|
|
} |
61
|
|
|
return false; |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getMember() { |
66
|
|
|
return $this->member; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function setMember($member) { |
70
|
|
|
$this->member = $member; |
71
|
|
|
return $this; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function getJoinTable() { |
75
|
|
|
return $this->joinTable; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function setJoinTable($joinTable) { |
79
|
|
|
$this->joinTable = $joinTable; |
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getMyFkField() { |
84
|
|
|
return $this->myFkField; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function setMyFkField($myFkField) { |
88
|
|
|
$this->myFkField = $myFkField; |
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getFkField() { |
93
|
|
|
return $this->fkField; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setFkField($fkField) { |
97
|
|
|
$this->fkField = $fkField; |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function getTargetEntity() { |
102
|
|
|
return $this->targetEntity; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function setTargetEntity($targetEntity) { |
106
|
|
|
$this->targetEntity = $targetEntity; |
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function getTargetEntityClass() { |
111
|
|
|
return $this->targetEntityClass; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function setTargetEntityClass($targetEntityClass) { |
115
|
|
|
$this->targetEntityClass = $targetEntityClass; |
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getTargetEntityTable() { |
120
|
|
|
return $this->targetEntityTable; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function setTargetEntityTable($targetEntityTable) { |
124
|
|
|
$this->targetEntityTable = $targetEntityTable; |
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function getMyPk() { |
129
|
|
|
return $this->myPk; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function setMyPk($myPk) { |
133
|
|
|
$this->myPk = $myPk; |
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function getPk() { |
138
|
|
|
return $this->pk; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function setPk($pk) { |
142
|
|
|
$this->pk = $pk; |
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function getInversedBy() { |
147
|
|
|
return $this->inversedBy; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function setInversedBy($inversedBy) { |
151
|
|
|
$this->inversedBy = $inversedBy; |
152
|
|
|
return $this; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function getInstance() { |
156
|
|
|
return $this->instance; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function setInstance($instance) { |
160
|
|
|
$this->instance = $instance; |
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
|