1 <?php
2
3 4 5 6 7 8 9
10 class rex_sql_foreign_key
11 {
12 const RESTRICT = 'RESTRICT';
13 const CASCADE = 'CASCADE';
14 const SET_NULL = 'SET NULL';
15
16
17 private $name;
18
19
20 private $table;
21
22
23 private $columns;
24
25
26 private $onUpdate;
27
28
29 private $onDelete;
30
31 private $modified = false;
32
33 34 35 36 37 38 39
40 public function __construct($name, $table, array $columns, $onUpdate = self::RESTRICT, $onDelete = self::RESTRICT)
41 {
42 $this->name = $name;
43 $this->table = $table;
44 $this->columns = $columns;
45 $this->onUpdate = $onUpdate;
46 $this->onDelete = $onDelete;
47 }
48
49 50 51 52 53
54 public function setModified($modified)
55 {
56 $this->modified = $modified;
57
58 return $this;
59 }
60
61 62 63
64 public function isModified()
65 {
66 return $this->modified;
67 }
68
69 70 71 72 73
74 public function setName($name)
75 {
76 $this->name = $name;
77
78 return $this->setModified(true);
79 }
80
81 82 83
84 public function getName()
85 {
86 return $this->name;
87 }
88
89 90 91 92 93
94 public function setTable($table)
95 {
96 $this->table = $table;
97
98 return $this->setModified(true);
99 }
100
101 102 103
104 public function getTable()
105 {
106 return $this->table;
107 }
108
109 110 111 112 113
114 public function setColumns(array $columns)
115 {
116 $this->columns = $columns;
117
118 return $this->setModified(true);
119 }
120
121 122 123
124 public function getColumns()
125 {
126 return $this->columns;
127 }
128
129 130 131 132 133
134 public function setOnUpdate($onUpdate)
135 {
136 $this->onUpdate = $onUpdate;
137
138 return $this->setModified(true);
139 }
140
141 142 143
144 public function getOnUpdate()
145 {
146 return $this->onUpdate;
147 }
148
149 150 151 152 153
154 public function setOnDelete($onDelete)
155 {
156 $this->onDelete = $onDelete;
157
158 return $this->setModified(true);
159 }
160
161 162 163
164 public function getOnDelete()
165 {
166 return $this->onDelete;
167 }
168
169 170 171
172 public function equals(self $index)
173 {
174 return
175 $this->name === $index->name &&
176 $this->table === $index->table &&
177 $this->columns == $index->columns &&
178 $this->onUpdate === $index->onUpdate &&
179 $this->onDelete === $index->onDelete;
180 }
181 }
182