Skip to content

Commit

Permalink
配置参数统一使用驼峰命名
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Feb 20, 2025
1 parent 778a8da commit b0904aa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
13 changes: 6 additions & 7 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ public function __construct(array | object $data = [])
'relation' => [],
'together' => [],
'allow' => [],
'with_attr' => [],
'withAttr' => [],
'schema' => $options['schema'] ?? [],
'update_time' => $options['update_time'] ?? 'update_time',
'create_time' => $options['create_time'] ?? 'create_time',
'updateTime' => $options['updateTtime'] ?? 'update_time',
'createTime' => $options['createTime'] ?? 'create_time',
'suffix' => $options['suffix'] ?? '',
'pk' => $options['pk'] ?? 'id',
'validate' => $options['validate'] ?? $this->parseValidate(),
Expand All @@ -130,9 +130,8 @@ public function __construct(array | object $data = [])
'append' => $options['append'] ?? [],
'mapping' => $options['mapping'] ?? [],
'strict' => $options['strict'] ?? true,
'bind_attr' => $options['bind_attr'] ?? [],
'auto_relation' => $options['auto_relation'] ?? [],
'relation_keys' => $options['relation_keys'] ?? [],
'bindAttr' => $options['bindAttr'] ?? [],
'autoRelation' => $options['autoRelation'] ?? [],
];

// 设置额外参数
Expand Down Expand Up @@ -594,7 +593,7 @@ public function __get(string $name)
*/
public function __set(string $name, $value): void
{
if ($value instanceof Modelable && $bind = $this->getBindAttr($this->getOption('bind_attr'), $name)) {
if ($value instanceof Modelable && $bind = $this->getBindAttr($this->getOption('bindAttr'), $name)) {
// 关联属性绑定
$this->bindRelationAttr($value, $bind);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/model/concern/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function withAttr(string $name, callable $callback)
{
$name = $this->getRealFieldName($name);

$this->setWeakData('with_attr', $name, $callback);
$this->setWeakData('withAttr', $name, $callback);
// 自动追加输出
self::$weakMap[$this]['append'][] = $name;
return $this;
Expand Down Expand Up @@ -565,7 +565,7 @@ private function getWithAttr(string $name, $value, array $data = [])
{
$attr = Str::studly($name);
$method = 'get' . $attr . 'Attr';
$withAttr = $this->getWeakData('with_attr', $name);
$withAttr = $this->getWeakData('withAttr', $name);
if ($withAttr) {
// 动态获取器
$value = $withAttr($value, $data, $this);
Expand Down
4 changes: 2 additions & 2 deletions src/model/concern/DbConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ public static function __callStatic($method, $args)

$db = $model->getQuery();

if (!empty(self::$weakMap[$model]['auto_relation'])) {
if (!empty(self::$weakMap[$model]['autoRelation'])) {
// 自动获取关联数据
$db->with(self::$weakMap[$model]['auto_relation']);
$db->with(self::$weakMap[$model]['autoRelation']);
}

return call_user_func_array([$db, $method], $args);
Expand Down
2 changes: 1 addition & 1 deletion src/model/concern/RelationShip.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function parseRelationData(array $relations)
foreach ($relations as $relation => $val) {
$relation = $this->getRealFieldName($relation);
$type = $this->getFields($relation);
$bind = $this->getBindAttr($this->getOption('bind_attr'), $relation);
$bind = $this->getBindAttr($this->getOption('bindAttr'), $relation);
if (!empty($bind)) {
// 绑定关联属性
$this->bindRelationAttr($val, $bind);
Expand Down

0 comments on commit b0904aa

Please sign in to comment.