glpi / src / plugins / vigilo / Vigilo / VigiloTest.php @ 166be9d2
History | View | Annotate | Download (1.31 KB)
1 | 166be9d2 | Francois POIROTTE | <?php
|
---|---|---|---|
2 | |||
3 | class VigiloTest extends VigiloXml implements ArrayAccess |
||
4 | { |
||
5 | protected $name; |
||
6 | protected $args; |
||
7 | |||
8 | public function __construct($name, array $args = array()) |
||
9 | { |
||
10 | $this->name = $name; |
||
11 | $this->args = array(); |
||
12 | |||
13 | foreach ($args as $arg) { |
||
14 | $this[] = $arg; |
||
15 | } |
||
16 | } |
||
17 | |||
18 | public function offsetExists($offset) |
||
19 | { |
||
20 | $name = is_a($offset, 'VigiloArg') ? $offset->getName() : $offset; |
||
21 | return isset($this->args[$name]); |
||
22 | } |
||
23 | |||
24 | public function offsetGet($offset) |
||
25 | { |
||
26 | $name = is_a($offset, 'VigiloArg') ? $offset->getName() : $offset; |
||
27 | return isset($this->args[$name]) ? $this->args[$name] : null; |
||
28 | } |
||
29 | |||
30 | public function offsetSet($offset, $value) |
||
31 | { |
||
32 | if (is_string($offset)) { |
||
33 | $value = new VigiloArg($offset, $value); |
||
34 | } |
||
35 | |||
36 | if (!is_a($value, 'VigiloArg')) { |
||
37 | throw new \RuntimeException(); |
||
38 | } |
||
39 | |||
40 | return $this->args[$value->getName()] = $value; |
||
41 | } |
||
42 | |||
43 | public function offsetUnset($offset) |
||
44 | { |
||
45 | $name = is_a($offset, 'VigiloArg') ? $offset->getName() : $offset; |
||
46 | unset($this->args[$name]); |
||
47 | } |
||
48 | |||
49 | public function __toString() |
||
50 | { |
||
51 | return self::sprintf( |
||
52 | '<test name="%s">%s</test>',
|
||
53 | $this->name,
|
||
54 | $this->args
|
||
55 | ); |
||
56 | } |
||
57 | } |