1 | <?php |
||
21 | trait Accessors |
||
22 | { |
||
23 | private $_magic = []; |
||
24 | |||
25 | 14 | public function __get($property) |
|
26 | { |
||
27 | 14 | $getter = 'get' . ucfirst($property); |
|
28 | |||
29 | 14 | if (method_exists($this, $getter)) { |
|
30 | 14 | return $this->$getter(); |
|
31 | } elseif (method_exists($this, 'set' . ucfirst($property))) { |
||
32 | throw new WriteOnlyException("Property \$$property is write-only, which is rather strange. Maybe you should write custom getter with proper explanation?"); |
||
33 | } else { |
||
34 | return $this->_get($property); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | 15 | public function __set($property, $value) |
|
39 | { |
||
40 | 15 | $setter = 'set' . ucfirst($property); |
|
41 | |||
42 | 15 | if (method_exists($this, $setter)) { |
|
43 | 15 | $this->$setter($value); |
|
44 | 8 | } elseif (method_exists($this, 'get' . ucfirst($property))) { |
|
45 | throw new ReadOnlyException("Property \$$property is read-only."); |
||
46 | } else { |
||
47 | 8 | $this->_magic[$property] = $value; |
|
48 | } |
||
49 | 15 | } |
|
50 | |||
51 | 1 | public function __isset($property) |
|
52 | { |
||
53 | 1 | return $this->$property !== null; |
|
54 | } |
||
55 | |||
56 | public function __unset($property) |
||
60 | |||
61 | public function _get($property) |
||
65 | |||
66 | public function _set($property, $value) |
||
70 | |||
71 | 14 | public function applyOptions(array $options) |
|
72 | { |
||
77 | } |
||
78 |