@@ -173,26 +173,12 @@ private function parseDataEntities()
173
173
$ uniquenessValues = [];
174
174
175
175
if (array_key_exists (self ::DATA_VALUES , $ entity )) {
176
- foreach ($ entity [self ::DATA_VALUES ] as $ dataElement ) {
177
- $ dataElementKey = strtolower ($ dataElement [self ::DATA_ELEMENT_KEY ]);
178
- $ dataElementValue = $ dataElement [self ::DATA_ELEMENT_VALUE ] ?? "" ;
179
- if (array_key_exists (self ::DATA_ELEMENT_UNIQUENESS_ATTR , $ dataElement )) {
180
- $ uniquenessValues [$ dataElementKey ] = $ dataElement [self ::DATA_ELEMENT_UNIQUENESS_ATTR ];
181
- }
182
-
183
- $ dataValues [$ dataElementKey ] = $ dataElementValue ;
184
- }
185
- unset($ dataElement );
176
+ $ dataValues = $ this ->parseDataElements ($ entity );
177
+ $ uniquenessValues = $ this ->parseUniquenessValues ($ entity );
186
178
}
187
179
188
180
if (array_key_exists (self ::REQUIRED_ENTITY , $ entity )) {
189
- foreach ($ entity [self ::REQUIRED_ENTITY ] as $ linkedEntity ) {
190
- $ linkedEntityName = $ linkedEntity [self ::REQUIRED_ENTITY_VALUE ];
191
- $ linkedEntityType = $ linkedEntity [self ::REQUIRED_ENTITY_TYPE ];
192
-
193
- $ linkedEntities [$ linkedEntityName ] = $ linkedEntityType ;
194
- }
195
- unset($ linkedEntity );
181
+ $ linkedEntities = $ this ->parseRequiredEntityElements ($ entity );
196
182
}
197
183
198
184
if (array_key_exists (self ::ARRAY_VALUES , $ entity )) {
@@ -207,11 +193,7 @@ private function parseDataEntities()
207
193
}
208
194
209
195
if (array_key_exists (self ::VAR_VALUES , $ entity )) {
210
- foreach ($ entity [self ::VAR_VALUES ] as $ varElement ) {
211
- $ varKey = $ varElement [self ::VAR_KEY ];
212
- $ varValue = $ varElement [self ::VAR_ENTITY ] . self ::VAR_ENTITY_FIELD_SEPARATOR . $ varElement [self ::VAR_FIELD ];
213
- $ vars [$ varKey ] = $ varValue ;
214
- }
196
+ $ vars = $ this ->parseVarElements ($ entity );
215
197
}
216
198
217
199
$ entityDataObject = new EntityDataObject (
@@ -224,9 +206,74 @@ private function parseDataEntities()
224
206
);
225
207
226
208
$ this ->data [$ entityDataObject ->getName ()] = $ entityDataObject ;
227
-
228
209
}
229
210
unset($ entityName );
230
211
unset($ entity );
231
212
}
213
+
214
+ /**
215
+ * Parses <data> elements in an entity, and returns them as an array of "lowerKey"=>value.
216
+ * @param array $entityData
217
+ * @return array
218
+ */
219
+ private function parseDataElements ($ entityData )
220
+ {
221
+ $ dataValues = [];
222
+ foreach ($ entityData [self ::DATA_VALUES ] as $ dataElement ) {
223
+ $ dataElementKey = strtolower ($ dataElement [self ::DATA_ELEMENT_KEY ]);
224
+ $ dataElementValue = $ dataElement [self ::DATA_ELEMENT_VALUE ] ?? "" ;
225
+ $ dataValues [$ dataElementKey ] = $ dataElementValue ;
226
+ }
227
+ return $ dataValues ;
228
+ }
229
+
230
+ /**
231
+ * Parses through <data> elements in an entity to return an array of "DataKey" => "UniquenessAttribute"
232
+ * @param array $entityData
233
+ * @return array
234
+ */
235
+ private function parseUniquenessValues ($ entityData )
236
+ {
237
+ $ uniquenessValues = [];
238
+ foreach ($ entityData [self ::DATA_VALUES ] as $ dataElement ) {
239
+ if (array_key_exists (self ::DATA_ELEMENT_UNIQUENESS_ATTR , $ dataElement )) {
240
+ $ dataElementKey = strtolower ($ dataElement [self ::DATA_ELEMENT_KEY ]);
241
+ $ uniquenessValues [$ dataElementKey ] = $ dataElement [self ::DATA_ELEMENT_UNIQUENESS_ATTR ];
242
+ }
243
+ }
244
+ return $ uniquenessValues ;
245
+ }
246
+
247
+ /**
248
+ * Parses <required-entity> elements given entity, and returns them as an array of "EntityValue"=>"EntityType"
249
+ * @param array $entityData
250
+ * @return array
251
+ */
252
+ private function parseRequiredEntityElements ($ entityData )
253
+ {
254
+ $ linkedEntities = [];
255
+ foreach ($ entityData [self ::REQUIRED_ENTITY ] as $ linkedEntity ) {
256
+ $ linkedEntityName = $ linkedEntity [self ::REQUIRED_ENTITY_VALUE ];
257
+ $ linkedEntityType = $ linkedEntity [self ::REQUIRED_ENTITY_TYPE ];
258
+
259
+ $ linkedEntities [$ linkedEntityName ] = $ linkedEntityType ;
260
+ }
261
+ return $ linkedEntities ;
262
+ }
263
+
264
+ /**
265
+ * Parses <var> elements in given entity, and returns them as an array of "Key"=> entityType -> entityKey
266
+ * @param array $entityData
267
+ * @return array
268
+ */
269
+ private function parseVarElements ($ entityData )
270
+ {
271
+ $ vars = [];
272
+ foreach ($ entityData [self ::VAR_VALUES ] as $ varElement ) {
273
+ $ varKey = $ varElement [self ::VAR_KEY ];
274
+ $ varValue = $ varElement [self ::VAR_ENTITY ] . self ::VAR_ENTITY_FIELD_SEPARATOR . $ varElement [self ::VAR_FIELD ];
275
+ $ vars [$ varKey ] = $ varValue ;
276
+ }
277
+ return $ vars ;
278
+ }
232
279
}
0 commit comments