1: <?php
2:
3: /**
4: * A structure containing other XMLRPCParameter objects.
5: *
6: * @package Elgg.Core
7: * @subpackage XMLRPC
8: */
9: class XMLRPCStructParameter extends XMLRPCParameter {
10: /**
11: * Construct a struct.
12: *
13: * @param array $parameters Optional associated array of parameters, if
14: * not provided then addField must be used.
15: */
16: function __construct($parameters = NULL) {
17: parent::__construct();
18:
19: if (is_array($parameters)) {
20: foreach ($parameters as $k => $v) {
21: $this->addField($k, $v);
22: }
23: }
24: }
25:
26: /**
27: * Add a field to the container.
28: *
29: * @param string $name The name of the field.
30: * @param XMLRPCParameter $value The value.
31: *
32: * @return void
33: */
34: public function addField($name, XMLRPCParameter $value) {
35: if (!is_array($this->value)) {
36: $this->value = array();
37: }
38:
39: $this->value[$name] = $value;
40: }
41:
42: /**
43: * Convert to string
44: *
45: * @return string
46: */
47: function __toString() {
48: $params = "";
49: foreach ($this->value as $k => $v) {
50: $params .= "<member><name>$k</name>$v</member>";
51: }
52:
53: return "<value><struct>$params</struct></value>";
54: }
55: }
56: