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