Commit 94d36efa by 王召彬

重新toArray()

parent e1c8d3dc
......@@ -14,6 +14,7 @@ use Swoft\Db\Bean\Collector\EntityCollector;
use Swoft\Db\Model;
use Swoft\Exception\Exception;
use Swoole\Http\Request;
use Swoft\Helper\StringHelper;
class CommonEntity extends Model
{
......@@ -183,4 +184,32 @@ class CommonEntity extends Model
preg_match('/(?<=Table\(name=").*(?="\))/', $commentString, $matches);
return $tableName = isset($matches[0])?$matches[0]:'';
}
/**
* @return array
*/
public function toArray(): array
{
$entities = EntityCollector::getCollector();
$columns = $entities[static::class]['field'];
$data = [];
foreach ($columns as $propertyName => $column) {
if (!isset($column['column'])) {
continue;
}
$methodName = StringHelper::camel('get' . $propertyName);
if (!\method_exists($this, $methodName)) {
continue;
}
$value = $this->$methodName();
if($value === null){
continue;
}
$data[$propertyName] = $value;
}
return $data;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment