glpi / src / plugins / vigilo / Vigilo / VigiloArg.php @ 8d255750
History | View | Annotate | Download (1.3 KB)
1 | bef4271a | Thibault Louet | <?php
|
---|---|---|---|
2 | |||
3 | class VigiloArg extends VigiloXml |
||
4 | { |
||
5 | protected $name; |
||
6 | protected $values; |
||
7 | |||
8 | public function __construct($name, $values) |
||
9 | { |
||
10 | if (is_array($values)) { |
||
11 | $new_values = array(); |
||
12 | foreach ($values as $value) { |
||
13 | a5c9df40 | Thibault Louet | if (is_string($value)) { |
14 | bef4271a | Thibault Louet | $new_values[] = new VigiloItem($value); |
15 | a5c9df40 | Thibault Louet | } elseif (!is_a($value, 'VigiloItem')) { |
16 | bef4271a | Thibault Louet | throw new \RuntimeException(); |
17 | a5c9df40 | Thibault Louet | } else {
|
18 | bef4271a | Thibault Louet | $new_values[] = $value; |
19 | a5c9df40 | Thibault Louet | } |
20 | bef4271a | Thibault Louet | } |
21 | $values = $new_values; |
||
22 | a5c9df40 | Thibault Louet | } elseif (!is_string($values) && !is_int($values) |
23 | ad6689da | Francois POIROTTE | && !is_bool($values) && !is_float($values)) { |
24 | bef4271a | Thibault Louet | throw new \RuntimeException(); |
25 | a5c9df40 | Thibault Louet | } else {
|
26 | bef4271a | Thibault Louet | $values = (string) $values; |
27 | } |
||
28 | |||
29 | ad6689da | Francois POIROTTE | $this->name = $name; |
30 | $this->values = $values; |
||
31 | bef4271a | Thibault Louet | } |
32 | |||
33 | public function getName() |
||
34 | { |
||
35 | return $this->name; |
||
36 | } |
||
37 | |||
38 | public function getValue() |
||
39 | { |
||
40 | a5c9df40 | Thibault Louet | if (is_string($this->values)) { |
41 | bef4271a | Thibault Louet | return $this->values; |
42 | a5c9df40 | Thibault Louet | } |
43 | bef4271a | Thibault Louet | return array_map('getValue', $this->values); |
44 | } |
||
45 | |||
46 | public function __toString() |
||
47 | { |
||
48 | return self::sprintf( |
||
49 | '<arg name="%s">%s</arg>',
|
||
50 | $this->name,
|
||
51 | $this->values
|
||
52 | ); |
||
53 | } |
||
54 | a5c9df40 | Thibault Louet | } |