name = $name; $this->_ = $value; } function key() { return $this->name; } function value() { return $this->_; } } // class APIParam /** * Complex type 'item' */ class APIItem { public $id; // Attribute 'id' (integer) public $param; // Element(s) of complex type 'param' /** * @param integer $id - identifier of the item * @param mixed $param - APIParam object or array of them */ function __construct( $id, $param = null) { $this->id = $id; if (!is_null( $param)) $this->param = $param; } function key() { return intval( $this->id); } function value() { return $this->asArray(); } /** * Add one or multiple 'param' elements * * @param mixed $what - APIParam object, or array of them */ function add( $what) { if (is_a( $what, 'APIParam')) { if (!isset( $this->param)) $this->param = array(); $this->param[] = $what; } elseif (is_array( $what)) { foreach ($what as $item) $this->add( $item); } } /** * Get item description as array * @return array */ function asArray() { $a = array( 'id' => $this->id); if (is_array( $this->param)) { foreach ($this->param as $param) $a[ $param->name] = $param->_; } elseif (is_object( $this->param)) { $a[ $this->param->name] = $this->param->_; } return $a; } } // class APIItem /** * Complex type 'Message' */ class APIMessage { /* May contain following properties, both are optional. public $param; - Element(s) of complex type 'param' public $item; - Element(s) of complex type 'item' */ /** * APIMessage( $param, [...]) * Takes several parameters of APIParam, APIItem or array of them */ function __construct() { foreach (func_get_args() as $arg) $this->add( $arg); } /** * Add one or multiple 'param' or 'item' elements * * @param mixed $what - APIParam or APIItem object, or array of them */ function add( $what) { if (is_a( $what, 'APIParam')) { if (!isset( $this->param)) $this->param = array(); $this->param[] = $what; } elseif (is_a( $what, 'APIItem')) { if (!isset( $this->item)) $this->item = array(); $this->item[] = $what; } elseif (is_array( $what)) { foreach ($what as $item) $this->add( $item); } } /** * Return params or items as array * * @param string $what - 'param' or 'item' * @return array */ function asArray( $what) { $a = array(); if (is_array( $this->$what)) { foreach ($this->$what as $arg) $a[ $arg->key()] = $arg->value(); } elseif (is_object( $this->$what)) { $a[ $this->$what->key()] = $this->$what->value(); } return $a; } } // class APIMessage class APIGlobal { /** * Map XML complex types to PHP classes * @var array */ static $classmap = array( 'param' => 'APIParam', 'item' => 'APIItem', 'Message' => 'APIMessage', ); } // class APIGlobals