This commit is contained in:
2021-01-19 19:22:57 +08:00
parent 325bbcb999
commit a1384ba812
+18 -6
View File
@@ -314,24 +314,36 @@ class ActiveRecord extends BaseActiveRecord
$attributes = Snowflake::app()->getAttributes(); $attributes = Snowflake::app()->getAttributes();
$callback = $attributes->getByClass(static::class); $callback = $attributes->getByClass(static::class);
var_dump($callback);
$data = $this->_attributes; $data = $this->_attributes;
foreach ($callback as $key => $item) { foreach ($callback as $key => $item) {
$data = $this->resolveAttributes($item, $data);
}
return array_merge($data, $this->runRelate());
}
/**
* @param $item
* @param $data
* @return array
*/
private function resolveAttributes($item, $data): array
{
if (!isset($item['attributes'])) {
return $data;
}
foreach ($item['attributes'] as $attribute) { foreach ($item['attributes'] as $attribute) {
if (!($attribute instanceof Get)) { if (!($attribute instanceof Get)) {
continue; continue;
} }
$name = $attribute->name; $name = $attribute->name;
$result = call_user_func($item['handler'], $data[$name]); $result = call_user_func($item['handler'], $data[$name]);
$data[$name] = $result; $data[$name] = $result;
} }
return $data;
} }
return array_merge($data, $this->runRelate());
}
/** /**
* @return array * @return array