Completed
Push — master ( 1f90e4...0f8170 )
by Jean-Christophe
02:14
created

ManyToManyParser::setPk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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