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