Maileon PHP client  1.5.0
Easily integrate your PHP application with Maileon.
CustomFields.php
1 <?php
2 
9 {
10 
11  public $custom_fields;
12 
19  function __construct(
20  $custom_fields = array())
21  {
22  $this->custom_fields = $custom_fields;
23  }
24 
31  function fromXML($xmlElement)
32  {
33  foreach ($xmlElement->children() as $field) {
34  $this->custom_fields[trim($field->name)] = $field->type; // The trim is required to make a safer string from the object
35  }
36  }
37 
44  function toXML()
45  {
46  $xml = new SimpleXMLElement("<?xml version=\"1.0\"?><custom_fields></custom_fields>");
47  if (isset($this->custom_fields)) {
48  foreach ($this->custom_fields as $index => $type) {
49  $field = $xml->addChild("field");
50  $field->addChild("name", $index);
51  $field->addChild("type", $type);
52  }
53  }
54 
55  return $xml;
56  }
57 
64  function toXMLString()
65  {
66  $xml = $this->toXML();
67  return $xml->asXML();
68  }
69 
76  function toString()
77  {
78 
79  // Generate custom field string
80  $customfields = "";
81  if (isset($this->custom_fields)) {
82  foreach ($this->custom_fields as $index => $type) {
83  $customfields .= $index . "=" . $type . ", ";
84  }
85  $customfields = rtrim($customfields, ', ');
86  }
87 
88  return "CustomFields = {" . $customfields . "}";
89  }
90 }
__construct($custom_fields=array())