Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

glpi / src / Vigilo / VigiloArg.php @ 077e4de7

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
        ) {
25
            throw new \RuntimeException();
26
        } else {
27
            $values = (string) $values;
28
        }
29

    
30
        $this->name = $name;
31
        $this->values = $values;
32
    }
33

    
34
    public function getName()
35
    {
36
        return $this->name;
37
    }
38

    
39
    public function getValue()
40
    {
41
        if (is_string($this->values)) {
42
            return $this->values;
43
        }
44
        return array_map('getValue', $this->values);
45
    }
46

    
47
    public function __toString()
48
    {
49
        return self::sprintf(
50
            '<arg name="%s">%s</arg>',
51
            $this->name,
52
            $this->values
53
        );
54
    }
55
}