Maileon PHP client  1.2.5
Easily integrate your PHP application with Maileon.
JSONSerializer.php
1 <?php
16  static function json_encode($object) {
17  return json_encode(self::toArray($object));
18  }
19 
28  private static function toArray($object) {
29  $type = gettype($object);
30 
31  if($type == 'array') {
32  foreach($object as $element) {
33  // call this method on each object in the array
34  $result[]= self::toArray($element);
35  }
36 
37  // return the processed array
38  return $result;
39  } else if ($type == 'object') {
40  // if we can call toArray() on this object call it, otherwise return
41  // the object as-is and trigger a notice
42  if(is_subclass_of($object, 'com_maileon_api_json_AbstractJSONWrapper')) {
43  return $object->toArray();
44  } else {
45  trigger_error("com_maileon_api_json_JSONSerializer: Trying to serialize " . get_class($object));
46  return $object;
47  }
48  } else {
49  // if this is not an object we have nothing to do
50  return $object;
51  }
52  }
53 }