1 | <?php |
||
24 | class RowStructure implements \ArrayAccess |
||
25 | { |
||
26 | protected $primary_key = []; |
||
27 | protected $field_definitions = []; |
||
28 | protected $relation; |
||
29 | |||
30 | /** |
||
31 | * setDefinition |
||
32 | * |
||
33 | * Add a complete definition. |
||
34 | * |
||
35 | * @access public |
||
36 | * @param array $definition |
||
37 | * @return RowStructure $this |
||
38 | */ |
||
39 | public function setDefinition(array $definition) |
||
45 | |||
46 | /** |
||
47 | * inherits |
||
48 | * |
||
49 | * Add inherited structure. |
||
50 | * |
||
51 | * @access public |
||
52 | * @param RowStructure $structure |
||
53 | * @return RowStructure $this |
||
54 | */ |
||
55 | public function inherits(RowStructure $structure) |
||
63 | |||
64 | /** |
||
65 | * setRelation |
||
66 | * |
||
67 | * Set or change the relation. |
||
68 | * |
||
69 | * @access public |
||
70 | * @param string $relation |
||
71 | * @return RowStructure $this |
||
72 | */ |
||
73 | public function setRelation($relation) |
||
79 | |||
80 | /** |
||
81 | * setPrimaryKey |
||
82 | * |
||
83 | * Set or change the primary key definition. |
||
84 | * |
||
85 | * @access public |
||
86 | * @param array $primary_key |
||
87 | * @return RowStructure $this |
||
88 | */ |
||
89 | public function setPrimaryKey(array $primary_key) |
||
95 | |||
96 | /** |
||
97 | * addField |
||
98 | * |
||
99 | * Add a new field structure. |
||
100 | * |
||
101 | * @access public |
||
102 | * @param string $name |
||
103 | * @param string $type |
||
104 | * @throws ModelException if type or name is null |
||
105 | * @return RowStructure $this |
||
106 | */ |
||
107 | public function addField($name, $type) |
||
115 | |||
116 | /** |
||
117 | * getFieldNames |
||
118 | * |
||
119 | * Return an array of all field names |
||
120 | * |
||
121 | * @access public |
||
122 | * @return array |
||
123 | */ |
||
124 | public function getFieldNames() |
||
128 | |||
129 | /** |
||
130 | * hasField |
||
131 | * |
||
132 | * Check if a field exist in the structure |
||
133 | * |
||
134 | * @access public |
||
135 | * @param string $name |
||
136 | * @throws ModelException if $name is null |
||
137 | * @return bool |
||
138 | */ |
||
139 | public function hasField($name) |
||
143 | |||
144 | /** |
||
145 | * getTypeFor |
||
146 | * |
||
147 | * Return the type associated with the field |
||
148 | * |
||
149 | * @access public |
||
150 | * @param string $name |
||
151 | * @throws ModelException if $name is null or name does not exist. |
||
152 | * @return string $type |
||
153 | */ |
||
154 | public function getTypeFor($name) |
||
158 | |||
159 | /** |
||
160 | * getDefinition |
||
161 | * |
||
162 | * Return all fields and types |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | public function getDefinition() |
||
170 | |||
171 | /** |
||
172 | * getRelation |
||
173 | * |
||
174 | * Return the relation name. |
||
175 | * |
||
176 | * @access public |
||
177 | * @return string |
||
178 | */ |
||
179 | public function getRelation() |
||
183 | |||
184 | /** |
||
185 | * getPrimaryKey |
||
186 | * |
||
187 | * Return the primary key definition. |
||
188 | * |
||
189 | * @access public |
||
190 | * @return array |
||
191 | */ |
||
192 | public function getPrimaryKey() |
||
196 | |||
197 | /** |
||
198 | * checkNotNull |
||
199 | * |
||
200 | * Test if given value is null. |
||
201 | * |
||
202 | * @access private |
||
203 | * @param string $val |
||
204 | * @param string $name |
||
205 | * @throws \InvalidArgumentException if $val is null |
||
206 | * @return RowStructure $this |
||
207 | */ |
||
208 | private function checkNotNull($val, $name) |
||
216 | |||
217 | /** |
||
218 | * checkExist |
||
219 | * |
||
220 | * Test if a field exist. |
||
221 | * |
||
222 | * @access private |
||
223 | * @param string $name |
||
224 | * @throws ModelException if $name does not exist. |
||
225 | * @return RowStructure $this |
||
226 | */ |
||
227 | private function checkExist($name) |
||
242 | |||
243 | /** |
||
244 | * @see \ArrayAccess |
||
245 | */ |
||
246 | public function offsetSet($name, $type) |
||
250 | |||
251 | /** |
||
252 | * @see \ArrayAccess |
||
253 | */ |
||
254 | public function offsetGet($name) |
||
258 | |||
259 | /** |
||
260 | * @see \ArrayAccess |
||
261 | */ |
||
262 | public function offsetExists($name) |
||
266 | |||
267 | /** |
||
268 | * @see \ArrayAccess |
||
269 | */ |
||
270 | public function offsetUnset($name) |
||
274 | } |
||
275 |