1: | <?php |
2: | |
3: | namespace Zippy\Binding; |
4: | |
5: | use Zippy\Interfaces\Binding; |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | class PropertyBinding implements Binding |
13: | { |
14: | protected $obj = null; |
15: | protected $propertyname = ""; |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | public function __construct($obj, $propertyname) { |
33: | $this->obj = $obj; |
34: | $this->propertyname = $propertyname; |
35: | } |
36: | |
37: | public function getValue() { |
38: | if (false) { |
39: | if (!in_array($this->propertyname, array_keys(get_object_vars($this->obj)), false)) { |
40: | throw new \Zippy\Exception(sprintf(ERROR_NOT_FOUND_PROPERTY_BINDING, $this->propertyname, get_class($this->obj))); |
41: | }; |
42: | } |
43: | return $this->obj->{$this->propertyname}; |
44: | } |
45: | |
46: | public function getPropertyName() { |
47: | return $this->propertyname; |
48: | } |
49: | |
50: | public function setValue($data) { |
51: | if (false) { |
52: | if (!in_array($this->propertyname, array_keys(get_object_vars($this->obj)), false)) { |
53: | throw new \Zippy\Exception(sprintf(ERROR_NOT_FOUND_PROPERTY_BINDING, $this->propertyname, get_class($this->obj))); |
54: | }; |
55: | } |
56: | $this->obj->{$this->propertyname} = $data; |
57: | } |
58: | |
59: | } |
60: | |