Completed
Push — master ( ac3b2a...67ef21 )
by Jean-Christophe
02:07
created

ManyToManyParser::getInversedBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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