Decorator.php in Devel 4.x
File
webprofiler/src/Decorator.php
View source
<?php
namespace Drupal\webprofiler;
class Decorator {
protected $object;
public function __construct($object) {
$this->object = $object;
}
public function getOriginalObject() {
$object = $this->object;
while ($object instanceof Decorator) {
$object = $object
->getOriginalObject();
}
return $object;
}
public function isCallable($method, $checkSelf = FALSE) {
$object = $this
->getOriginalObject();
if (is_callable([
$object,
$method,
])) {
return $object;
}
$object = $checkSelf ? $this : $this->object;
while ($object instanceof Decorator) {
if (is_callable([
$object,
$method,
])) {
return $object;
}
$object = $this->object;
}
return FALSE;
}
public function __call($method, $args) {
if ($object = $this
->isCallable($method)) {
return call_user_func_array([
$object,
$method,
], $args);
}
throw new \Exception('Undefined method - ' . get_class($this
->getOriginalObject()) . '::' . $method);
}
public function __get($property) {
$object = $this
->getOriginalObject();
if (property_exists($object, $property)) {
return $object->{$property};
}
return NULL;
}
}