XRL  latest
Simple XML-RPC Library (both client and server)
Struct.php
1 <?php
2 /*
3  * This file is part of XRL, a simple XML-RPC Library for PHP.
4  *
5  * Copyright (c) 2012, XRL Team. All rights reserved.
6  * XRL is licensed under the 3-clause BSD License.
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace fpoirotte\XRL\Types;
13 
21 {
23  public function get()
24  {
25  $res = array();
26  foreach ($this->value as $key => $val) {
27  $res[$key] = $val->get();
28  }
29  return $res;
30  }
31 
33  public function set($value)
34  {
35  if (!is_array($value)) {
36  throw new \InvalidArgumentException('A structure was expected');
37  }
38 
39  foreach ($value as $key => $val) {
40  if (!is_string($key) && !is_int($key)) {
41  throw new \InvalidArgumentException('A structure was expected');
42  }
43 
44  if (!($val instanceof \fpoirotte\XRL\Types\AbstractType)) {
45  throw new \InvalidArgumentException('A valid XML-RPC type was expected');
46  }
47  }
48 
49  $this->value = $value;
50  }
51 
53  public function write(\XMLWriter $writer, \DateTimeZone $timezone, $stringTag)
54  {
55  $writer->startElement('struct');
56  foreach ($this->value as $key => $val) {
57  $writer->startElement('member');
58  $writer->startElement('name');
59  $writer->text((string) $key);
60  $writer->endElement();
61  $writer->startElement('value');
62  $val->write($writer, $timezone, $stringTag);
63  $writer->endElement();
64  $writer->endElement();
65  }
66  $writer->endElement();
67  }
68 
70  protected static function parse($value, \DateTimeZone $timezone = null)
71  {
72  return array();
73  }
74 
87  public function offsetSet($offset, $value)
88  {
89  if (!is_string($offset)) {
90  throw new \InvalidArgumentException('A string offset was expected');
91  }
92  $this->value[$offset] = $value;
93  }
94 
104  public function offsetUnset($offset)
105  {
106  unset($this->value[$offset]);
107  }
108 
116  public function key()
117  {
118  $keys = array_keys($this->value);
119  return $keys[$this->index];
120  }
121 }
static parse($value,\DateTimeZone $timezone=null)
Definition: Struct.php:70
$index
Current index in the collection.
$value
Current value associated with this object.
offsetSet($offset, $value)
Definition: Struct.php:87
The XML-RPC "struct" type.
Definition: Struct.php:20
A class representing an abstract XML-RPC type.
An abstract XML-RPC type representing a collection of values.
write(\XMLWriter $writer,\DateTimeZone $timezone, $stringTag)
Definition: Struct.php:53