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 cad30c1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/View/ViewableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use InvalidArgumentException;
use IteratorAggregate;
use LogicException;
use ReflectionObject;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Config\Configurable;
Expand Down Expand Up @@ -155,13 +156,22 @@ public function __get($property)
public function __set($property, $value)
{
$this->objCacheClear();
if ($this->hasMethod($method = "set$property")) {
$method = "set$property";

if ($this->hasMethod($method) && !$this->isPrivate($this, $method)) {
$this->$method($value);
} else {
$this->setField($property, $value);
}
}

private function isPrivate(object $class, string $method): bool
{
$class = new ReflectionObject($class);

return $class->getMethod($method)->isPrivate();
}

/**
* Set a failover object to attempt to get data from if it is not present on this object.
*
Expand Down

0 comments on commit cad30c1

Please sign in to comment.