1 | <?php |
||
23 | abstract class AbstractDataObject extends stdClass |
||
24 | { |
||
25 | /** |
||
26 | * Construct method for class. Converts data (string via json_decode or |
||
27 | * array/object) to properties. |
||
28 | * |
||
29 | * @param mixed $data |
||
30 | */ |
||
31 | public function __construct($data = null) |
||
32 | { |
||
33 | $objectData = array(); |
||
34 | |||
35 | if (is_string($data)) { |
||
36 | $objectData = json_decode($data); |
||
37 | } elseif (is_array($data) || is_object($data)) { |
||
38 | $objectData = $data; |
||
39 | } |
||
40 | |||
41 | foreach ($objectData as $key => $value) { |
||
42 | $this->$key = $value; |
||
43 | } |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Get property from object. |
||
48 | * |
||
49 | * @param string $property Property name |
||
50 | * |
||
51 | * @return mixed Property value |
||
52 | */ |
||
53 | public function __get($property) |
||
54 | { |
||
55 | if (property_exists($this, $property)) { |
||
56 | return $this->$property; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Set property on object |
||
62 | * |
||
63 | * @param string $name Property name |
||
64 | * @param mixed $value Property value |
||
65 | */ |
||
66 | public function __set($name, $value) |
||
70 | |||
71 | /** |
||
72 | * Returns id extracted from uri. Uses getIdFromUri method in ContentApiSdk |
||
73 | * class. |
||
74 | * |
||
75 | * @return string Urldecoded id |
||
76 | */ |
||
77 | public function getId() |
||
81 | } |
||
82 |