1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\View; |
4
|
|
|
|
5
|
|
|
class ViewableData_Customised extends ViewableData |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @var ViewableData |
10
|
|
|
*/ |
11
|
|
|
protected $original, $customised; |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Instantiate a new customised ViewableData object |
15
|
|
|
* |
16
|
|
|
* @param ViewableData $originalObject |
17
|
|
|
* @param ViewableData $customisedObject |
18
|
|
|
*/ |
19
|
|
|
public function __construct(ViewableData $originalObject, ViewableData $customisedObject) |
20
|
|
|
{ |
21
|
|
|
$this->original = $originalObject; |
22
|
|
|
$this->customised = $customisedObject; |
23
|
|
|
|
24
|
|
|
$this->original->setCustomisedObj($this); |
25
|
|
|
|
26
|
|
|
parent::__construct(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function __call($method, $arguments) |
30
|
|
|
{ |
31
|
|
|
if ($this->customised->hasMethod($method)) { |
32
|
|
|
return call_user_func_array(array($this->customised, $method), $arguments); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return call_user_func_array(array($this->original, $method), $arguments); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function __get($property) |
39
|
|
|
{ |
40
|
|
|
if (isset($this->customised->$property)) { |
41
|
|
|
return $this->customised->$property; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->original->$property; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function __set($property, $value) |
48
|
|
|
{ |
49
|
|
|
$this->customised->$property = $this->original->$property = $value; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function __isset($property) |
53
|
|
|
{ |
54
|
|
|
return isset($this->customised->$property) || isset($this->original->$property) || parent::__isset($property); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function hasMethod($method) |
58
|
|
|
{ |
59
|
|
|
return $this->customised->hasMethod($method) || $this->original->hasMethod($method); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function cachedCall($field, $arguments = null, $identifier = null) |
63
|
|
|
{ |
64
|
|
|
if ($this->customised->hasMethod($field) || $this->customised->hasField($field)) { |
65
|
|
|
return $this->customised->cachedCall($field, $arguments, $identifier); |
66
|
|
|
} |
67
|
|
|
return $this->original->cachedCall($field, $arguments, $identifier); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function obj($fieldName, $arguments = null, $cache = false, $cacheName = null) |
71
|
|
|
{ |
72
|
|
|
if ($this->customised->hasField($fieldName) || $this->customised->hasMethod($fieldName)) { |
73
|
|
|
return $this->customised->obj($fieldName, $arguments, $cache, $cacheName); |
74
|
|
|
} |
75
|
|
|
return $this->original->obj($fieldName, $arguments, $cache, $cacheName); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.