glpi / src / plugins / vigilo / Vigilo / VigiloArg.php @ fbdbbd6a
History | View | Annotate | Download (1.3 KB)
1 |
<?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 |
if (is_string($value)) { |
14 |
$new_values[] = new VigiloItem($value); |
15 |
} elseif (!is_a($value, 'VigiloItem')) { |
16 |
throw new \RuntimeException(); |
17 |
} else {
|
18 |
$new_values[] = $value; |
19 |
} |
20 |
} |
21 |
$values = $new_values; |
22 |
} elseif (!is_string($values) && !is_int($values) |
23 |
&& !is_bool($values) && !is_float($values)) { |
24 |
throw new \RuntimeException(); |
25 |
} else {
|
26 |
$values = (string) $values; |
27 |
} |
28 |
|
29 |
$this->name = $name; |
30 |
$this->values = $values; |
31 |
} |
32 |
|
33 |
public function getName() |
34 |
{ |
35 |
return $this->name; |
36 |
} |
37 |
|
38 |
public function getValue() |
39 |
{ |
40 |
if (is_string($this->values)) { |
41 |
return $this->values; |
42 |
} |
43 |
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 |
} |