Skip to content

Commit

Permalink
Check is_callable parent methods before invoke
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Jan 11, 2023
1 parent 0d3953b commit 0f722f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2842,29 +2842,29 @@ public function setField($fieldName, $val)
// later referenced to update the parent dataobject
if ($val instanceof DBComposite) {
$val->bindTo($this);
$this->setFieldValue($fieldName, $val);
$this->setDBFieldValue($fieldName, $val);
}
// Situation 2: Passing a literal or non-DBField object
} else {
$this->setFieldValue($fieldName, $val);
$this->setDBFieldValue($fieldName, $val);
}
return $this;
}

private function setFieldValue(string $fieldName, mixed $val): void
private function setDBFieldValue(string $fieldName, mixed $val): void
{
$schema = static::getSchema();
// If this is a proper database field, we shouldn't be getting non-DBField objects
if (is_object($val) && !($val instanceof DBField) && $schema->fieldSpec(static::class, $fieldName)) {
throw new InvalidArgumentException('DataObject::setFieldValue: passed an object that is not a DBField');
throw new InvalidArgumentException('DataObject::setDBFieldValue: passed an object that is not a DBField');
}

if (!empty($val) && !is_scalar($val)) {
$dbField = $this->dbObject($fieldName);
if ($dbField && $dbField->scalarValueOnly()) {
throw new InvalidArgumentException(
sprintf(
'DataObject::setFieldValue: %s only accepts scalars',
'DataObject::setDBFieldValue: %s only accepts scalars',
$fieldName
)
);
Expand Down
4 changes: 3 additions & 1 deletion src/View/ViewableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ public function __get($property)
public function __set($property, $value)
{
$this->objCacheClear();
if ($this->hasMethod($method = "set$property")) {
$method = "set$property";

if ($this->hasMethod($method) && is_callable([$this, $method])) {
$this->$method($value);
} else {
$this->setField($property, $value);
Expand Down

0 comments on commit 0f722f5

Please sign in to comment.