Skip to content

Commit

Permalink
create and update tuples with map types / fix #64
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Sep 10, 2021
1 parent b711453 commit abd6478
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 13 additions & 0 deletions php/Job/Entity/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public function run(Converter $converter): array
$type = $space->getProperty($k)['type'];
if ($type === 'uuid') {
$v = new Uuid($v);
} elseif ($type == 'map') {
if ($v !== null) {
if (is_string($v)) {
$v = json_decode($v);
}
if (!is_array($v) && !is_object($v)) {
throw new Exception("Invalid type for '$k' ($type): $values[$k]");
}
$v = $converter->toArray($v);
if (!count($v)) {
$v = null;
}
}
} elseif (is_object($v)) {
$v = $converter->toArray($v);
}
Expand Down
19 changes: 17 additions & 2 deletions php/Job/Entity/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,23 @@ public function run(Converter $converter): void
$type = $space->getProperty($k)['type'];
if ($type === 'uuid') {
$v = new Uuid($v);
} elseif (is_object($v)) {
$v = $converter->toArray($v);
} elseif ($type == 'map') {
if ($v !== null) {
if (is_string($v)) {
$v = json_decode($v);
}
if (!is_array($v) && !is_object($v)) {
$extra = '';
if (is_string($this->values->$k)) {
$extra .= ': ' . $this->values->$k;
}
throw new Exception("Invalid type for '$k' ($type)$extra");
}
$v = $converter->toArray($v);
if (!count($v)) {
$v = null;
}
}
}
$entity->$k = $v;
}
Expand Down

0 comments on commit abd6478

Please sign in to comment.