silverstripe-framework/src/View/ViewableData_Customised.php

78 lines
2.2 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\View;
class ViewableData_Customised extends ViewableData
{
2016-11-29 00:31:16 +01:00
/**
* @var ViewableData
*/
protected $original, $customised;
2016-11-29 00:31:16 +01:00
/**
* Instantiate a new customised ViewableData object
*
* @param ViewableData $originalObject
* @param ViewableData $customisedObject
*/
public function __construct(ViewableData $originalObject, ViewableData $customisedObject)
{
$this->original = $originalObject;
$this->customised = $customisedObject;
2016-11-29 00:31:16 +01:00
$this->original->setCustomisedObj($this);
2016-11-29 00:31:16 +01:00
parent::__construct();
}
2016-11-29 00:31:16 +01:00
public function __call($method, $arguments)
{
if ($this->customised->hasMethod($method)) {
return call_user_func_array(array($this->customised, $method), $arguments);
}
2016-11-29 00:31:16 +01:00
return call_user_func_array(array($this->original, $method), $arguments);
}
2016-11-29 00:31:16 +01:00
public function __get($property)
{
if (isset($this->customised->$property)) {
return $this->customised->$property;
}
2016-11-29 00:31:16 +01:00
return $this->original->$property;
}
2016-11-29 00:31:16 +01:00
public function __set($property, $value)
{
$this->customised->$property = $this->original->$property = $value;
}
public function __isset($property)
{
return isset($this->customised->$property) || isset($this->original->$property) || parent::__isset($property);
}
2016-11-29 00:31:16 +01:00
public function hasMethod($method)
{
return $this->customised->hasMethod($method) || $this->original->hasMethod($method);
}
2016-11-29 00:31:16 +01:00
public function cachedCall($field, $arguments = null, $identifier = null)
{
if ($this->customised->hasMethod($field) || $this->customised->hasField($field)) {
return $this->customised->cachedCall($field, $arguments, $identifier);
}
return $this->original->cachedCall($field, $arguments, $identifier);
}
2016-11-29 00:31:16 +01:00
public function obj($fieldName, $arguments = null, $cache = false, $cacheName = null)
{
if ($this->customised->hasField($fieldName) || $this->customised->hasMethod($fieldName)) {
return $this->customised->obj($fieldName, $arguments, $cache, $cacheName);
}
return $this->original->obj($fieldName, $arguments, $cache, $cacheName);
}
}