DbObject: re-order method checks when setting

This commit is contained in:
Thomas Gelf 2015-11-02 09:23:41 +01:00
parent 8433a57bc6
commit ccf47171fe
1 changed files with 14 additions and 9 deletions

View File

@ -257,9 +257,6 @@ abstract class DbObject
if ($value === '') {
$value = null;
}
if (! $this->hasProperty($key)) {
throw new IE('Trying to set invalid key %s', $key);
}
$func = 'validate' . ucfirst($key);
if (method_exists($this, $func) && $this->$func($value) !== true) {
throw new IE('Got invalid value "%s" for "%s"', $value, $key);
@ -268,20 +265,28 @@ abstract class DbObject
if (method_exists($this, $func)) {
$value = $this->$func($value);
}
if ($value === $this->get($key)) {
return $this;
}
if ($key === $this->getKeyName() && $this->hasBeenLoadedFromDb()) {
throw new IE('Changing primary key is not allowed');
}
$func = 'set' . ucfirst($key);
if (substr($func, -2) === '[]') {
$func = substr($func, 0, -2);
}
if (method_exists($this, $func)) {
return $this->$func($value);
}
if (! $this->hasProperty($key)) {
throw new IE('Trying to set invalid key %s', $key);
}
if ($value === $this->get($key)) {
return $this;
}
if ($key === $this->getKeyName() && $this->hasBeenLoadedFromDb()) {
throw new IE('Changing primary key is not allowed');
}
return $this->reallySet($key, $value);
}