|
@@ -38,6 +38,24 @@ class Entity {
|
|
|
$this->namespace = $namespace;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 返回表的字段
|
|
|
+ *
|
|
|
+ * @param string $table
|
|
|
+ * @return mixed
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
+ public function getTableInfo($table){
|
|
|
+ $db = $this->db();
|
|
|
+ if($db->isError()) {
|
|
|
+ throw new \Exception($db->getError());
|
|
|
+ }
|
|
|
+ $tableInfo = $db->getTableInfo($table);
|
|
|
+ if(!$tableInfo || empty($tableInfo['fields'])) {
|
|
|
+ throw new \Exception($table . ' does not have any field');
|
|
|
+ }
|
|
|
+ return $tableInfo;
|
|
|
+ }
|
|
|
/**
|
|
|
* 通过 Entity 获取数据表的字段
|
|
|
*
|
|
@@ -71,14 +89,7 @@ class Entity {
|
|
|
* @throws \Exception
|
|
|
*/
|
|
|
public function generateProperties($table, $className = '') {
|
|
|
- $db = $this->db();
|
|
|
- $tableInfo = $db->getTableInfo($table);
|
|
|
- if($db->isError()) {
|
|
|
- throw new \Exception($db->getError());
|
|
|
- }
|
|
|
- if(!$tableInfo || empty($tableInfo['fields'])) {
|
|
|
- throw new \Exception($table . ' does not have any field');
|
|
|
- }
|
|
|
+ $tableInfo = $this->getTableInfo($table);
|
|
|
$properties = [];
|
|
|
$docs = [];
|
|
|
$defaults = [];
|