This commit is contained in:
2024-12-23 10:03:35 +08:00
parent 7b4604ce98
commit b3f50fc6e4
+10 -7
View File
@@ -691,13 +691,16 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
*/ */
public function __set(string $name, mixed $value): void public function __set(string $name, mixed $value): void
{ {
if ($this->hasRelateMethod($name, 'set')) { $prefix = 'set' . ucfirst($name);
$this->{'set' . ucfirst($name)}($value); if (method_exists($name, $prefix)) {
$this->{$prefix}($value);
return;
}
$method = $prefix . 'Attribute';
if (method_exists($this, $method)) {
$this->_attributes[$name] = $this->{$method} ($value);
} else { } else {
$method = 'set' . ucfirst($name) . 'Attribute';
if (method_exists($this, $method)) {
$value = $this->{$method} ($value);
}
$this->_attributes[$name] = $value; $this->_attributes[$name] = $value;
} }
} }
@@ -711,7 +714,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
public function __get(string $name): mixed public function __get(string $name): mixed
{ {
$value = $this->_attributes[$name] ?? NULL; $value = $this->_attributes[$name] ?? NULL;
if (!$this->hasRelateMethod($name)) { if (!method_exists($this, 'get' . ucfirst($name))) {
return $this->withPropertyOverride($name, $value); return $this->withPropertyOverride($name, $value);
} else { } else {
return $this->withRelate($name); return $this->withRelate($name);