class Decorator in Devel 8
Same name and namespace in other branches
- 8.3 webprofiler/src/Decorator.php \Drupal\webprofiler\Decorator
- 8.2 webprofiler/src/Decorator.php \Drupal\webprofiler\Decorator
- 4.x webprofiler/src/Decorator.php \Drupal\webprofiler\Decorator
Generic class Decorator.
Hierarchy
- class \Drupal\webprofiler\Decorator
Expanded class hierarchy of Decorator
1 file declares its use of Decorator
- EntityDecorator.php in webprofiler/
src/ Entity/ EntityDecorator.php
File
- webprofiler/
src/ Decorator.php, line 8
Namespace
Drupal\webprofilerView source
class Decorator {
/**
* @var
*/
protected $object;
/**
* Class constructor.
*
* @param object $object
* The object to decorate.
*/
public function __construct($object) {
$this->object = $object;
}
/**
* Return the original (i.e. non decorated) object.
*
* @return mixed
* The original object.
*/
public function getOriginalObject() {
$object = $this->object;
while ($object instanceof Decorator) {
$object = $object
->getOriginalObject();
}
return $object;
}
/**
* Returns true if $method is a PHP callable.
*
* @param string $method
* The method name.
* @param bool $checkSelf
*
* @return bool|mixed
*/
public function isCallable($method, $checkSelf = FALSE) {
//Check the original object
$object = $this
->getOriginalObject();
if (is_callable([
$object,
$method,
])) {
return $object;
}
// Check Decorators.
$object = $checkSelf ? $this : $this->object;
while ($object instanceof Decorator) {
if (is_callable([
$object,
$method,
])) {
return $object;
}
$object = $this->object;
}
return FALSE;
}
/**
* @param $method
* @param $args
*
* @return mixed
*
* @throws \Exception
*/
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);
}
/**
* @param $property
*
* @return null
*/
public function __get($property) {
$object = $this
->getOriginalObject();
if (property_exists($object, $property)) {
return $object->{$property};
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Decorator:: |
protected | property | @var | |
Decorator:: |
public | function | Return the original (i.e. non decorated) object. | |
Decorator:: |
public | function | Returns true if $method is a PHP callable. | |
Decorator:: |
public | function | ||
Decorator:: |
public | function | Class constructor. | 2 |
Decorator:: |
public | function |