Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit e95b575

Browse files
Merge pull request #124 from melanger/patch-1
allow putting into subarrays in MetadataFromPerun
2 parents e9705cf + 3f48097 commit e95b575

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/MetadataFromPerun.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,18 @@ public function getMetadata($facility)
6363
foreach ($this->attributesDefinitions as $perunAttrName => $metadataAttrName) {
6464
$attribute = $facility[self::FACILITY_ATTRIBUTES][$perunAttrName];
6565
if ($attribute['value'] !== null) {
66-
$metadata[$metadataAttrName] = $attribute['value'];
66+
if ($attribute['value'] !== null) {
67+
$target = &$metadata;
68+
$keys = explode('>', $metadataAttrName);
69+
while (count($keys) > 1) {
70+
$key = array_shift($keys);
71+
if (!isset($target[$key])) {
72+
$target[$key] = [];
73+
}
74+
$target = &$target[$key];
75+
}
76+
$target[$keys[0]] = $attribute['value'];
77+
}
6778
}
6879
}
6980

0 commit comments

Comments
 (0)