1
0
Fork 0
mirror of synced 2024-07-06 23:21:05 +12:00

removes condition

This commit is contained in:
prateek banga 2023-08-10 20:00:13 +05:30
parent 02d4b6b612
commit 023e88ff56

View file

@ -493,43 +493,41 @@ class Response extends SwooleResponse
} }
} }
if ($data->isSet($key)) { if ($rule['array']) {
if ($rule['array']) { if (!is_array($document[$key])) {
if (!is_array($document[$key])) { throw new Exception($key . ' must be an array of type ' . $rule['type']);
throw new Exception($key . ' must be an array of type ' . $rule['type']); }
}
foreach ($document[$key] as $index => $item) { foreach ($document[$key] as $index => $item) {
if ($item instanceof Document) { if ($item instanceof Document) {
if (\is_array($rule['type'])) { if (\is_array($rule['type'])) {
foreach ($rule['type'] as $type) { foreach ($rule['type'] as $type) {
$condition = false; $condition = false;
foreach ($this->getModel($type)->conditions as $attribute => $val) { foreach ($this->getModel($type)->conditions as $attribute => $val) {
$condition = $item->getAttribute($attribute) === $val; $condition = $item->getAttribute($attribute) === $val;
if (!$condition) { if (!$condition) {
break;
}
}
if ($condition) {
$ruleType = $type;
break; break;
} }
} }
} else { if ($condition) {
$ruleType = $rule['type']; $ruleType = $type;
break;
}
} }
} else {
if (!array_key_exists($ruleType, $this->models)) { $ruleType = $rule['type'];
throw new Exception('Missing model for rule: ' . $ruleType);
}
$data[$key][$index] = $this->output($item, $ruleType);
} }
if (!array_key_exists($ruleType, $this->models)) {
throw new Exception('Missing model for rule: ' . $ruleType);
}
$data[$key][$index] = $this->output($item, $ruleType);
} }
} else { }
if ($document[$key] instanceof Document) { } else {
$data[$key] = $this->output($data[$key], $rule['type']); if ($document[$key] instanceof Document) {
} $data[$key] = $this->output($data[$key], $rule['type']);
} }
} }
$output[$key] = $data[$key]; $output[$key] = $data[$key];