2 namespace PayPal\Common;
5 * Generic Model class that all API domain classes extend
6 * Stores all member data in a hashmap that enables easy
7 * JSON encoding/decoding
11 private $_propMap = array();
13 public function __get($key) {
14 return $this->_propMap[$key];
17 public function __set($key, $value) {
18 $this->_propMap[$key] = $value;
21 public function __isset($key) {
22 return isset($this->_propMap[$key]);
25 public function __unset($key) {
26 unset($this->_propMap[$key]);
30 private function _convertToArray($param) {
32 foreach($param as $k => $v) {
33 if($v instanceof PPModel ) {
34 $ret[$k] = $v->toArray();
35 } else if (is_array($v)) {
36 $ret[$k] = $this->_convertToArray($v);
44 public function fromArray($arr) {
46 foreach($arr as $k => $v) {
48 $clazz = PPReflectionUtil::getPropertyClass(get_class($this), $k);
50 if(PPArrayUtil::isAssocArray($v)) {
56 foreach($v as $nk => $nv) {
65 $this->__set($k, $arr);
73 public function fromJson($json) {
74 $this->fromArray(json_decode($json, true));
77 public function toArray() {
78 return $this->_convertToArray($this->_propMap);
81 public function toJSON() {
82 return json_encode($this->toArray());