diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index 96dce4b8..90d1c5e9 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -12,8 +12,6 @@ namespace Database\Base; use Annotation\Event; use Annotation\Inject; -use Annotation\Model\Get; -use Annotation\Model\Set; use ArrayAccess; use Database\SqlBuilder; use Database\Traits\HasBase; @@ -75,8 +73,6 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess private array $_annotations = []; - private array $_fields = []; - /** * @var bool */ @@ -756,10 +752,7 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess */ public function has($attribute): bool { - if (empty($this->_fields)) { - $this->_fields = static::getColumns()->format(); - } - return isset($this->_fields[$attribute]); + return static::getColumns()->hasField($attribute); } /**ƒ diff --git a/Database/Mysql/Columns.php b/Database/Mysql/Columns.php index 73b9e9bd..60700105 100644 --- a/Database/Mysql/Columns.php +++ b/Database/Mysql/Columns.php @@ -55,6 +55,9 @@ class Columns extends Component */ private array $_auto_increment = []; + + private array $_fields = []; + /** * @param string $table * @return $this @@ -206,6 +209,31 @@ class Columns extends Component return $this->columns('Default', 'Field'); } + + /** + * @return mixed + * @throws Exception + */ + public function getFields(): array + { + if (empty($this->_fields)) { + $this->structure($this->table); + } + return $this->_fields[$this->table]; + } + + + /** + * @param $name + * @return bool + * @throws Exception + */ + public function hasField(string $name): bool + { + return isset($this->getFields()[$name]); + } + + /** * @return int|string|null * @throws Exception @@ -282,7 +310,6 @@ class Columns extends Component throw new Exception("The table " . $table . " not exists."); } return $this->columns[$table] = $this->resolve($column, $table); - } return $this->columns[$table]; } @@ -299,6 +326,9 @@ class Columns extends Component $this->addPrimary($item, $table); $column[$key]['Type'] = $this->clean($item['Type']); } + + $this->_fields[$table] = array_column($column, 'Default', 'Field'); + return $column; } diff --git a/HttpServer/Events/OnReceive.php b/HttpServer/Events/OnReceive.php index ed72d5ca..690a960d 100644 --- a/HttpServer/Events/OnReceive.php +++ b/HttpServer/Events/OnReceive.php @@ -36,7 +36,7 @@ class OnReceive extends Callback * @return mixed * @throws Exception */ - public function onHandler(\Swoole\Server $server, int $fd, int $reID, string $data): mixed + public function onHandler(Server $server, int $fd, int $reID, string $data): mixed { try { $client = $server->getClientInfo($fd, $reID);