Maileon PHP client  1.5.5
Easily integrate your PHP application with Maileon.
JSONDeserializer.php
1 <?php
2 
20  static function json_decode($jsonString, $deserializationType = null) {
21  if(is_array($deserializationType) && count($deserializationType) > 1) {
22  $type = $deserializationType[0];
23  $innerType = $deserializationType[1];
24  } else {
25  $type = $deserializationType;
26  $innerType = null;
27  }
28 
29 // return self::fromArray(json_decode($jsonString, true), $type, $innerType);
30  return self::fromArray(json_decode($jsonString), $type, $innerType);
31  }
32 
45  private static function fromArray($object, $type = null, $innerType = null) {
46  if($type == 'array') {
47  foreach ($object as $element) {
48  // call this method on each element
49  $result[]= self::fromArray($element, $innerType);
50  }
51 
52  // return the processed array
53  return $result;
54  } else if (class_exists($type)) {
55  // create the class we are deserializing
56  $class = new $type();
57 
58  // if we can call fromArray on the class call it, otherwise
59  // return the object as-is and trigger a warning
60  if(is_subclass_of($class, 'com_maileon_api_json_AbstractJSONWrapper')) {
61  $class->fromArray($object);
62  return $class;
63  } else {
64  trigger_error( __CLASS__ . ": Trying to deserialize " . get_class($class));
65  return $object;
66  }
67  } else {
68  // if this is not a class, we have nothing to do
69  return $object;
70  }
71  }
72 }
static json_decode($jsonString, $deserializationType=null)