Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

glpi / Vigilo / VigiloArg.php @ bef4271a

History | View | Annotate | Download (1.26 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
                else if (!is_a($value, 'VigiloItem'))
16
                    throw new \RuntimeException();
17
                else
18
                    $new_values[] = $value;
19
            }
20
            $values = $new_values;
21
        } else if (!is_string($values) && !is_int($values) &&
22
                   !is_bool($values) && !is_float($values))
23
            throw new \RuntimeException();
24
        else {
25
            $values = (string) $values;
26
        }
27

    
28
        $this->name = $name;
29
        $this->values = $values;
30
    }
31

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

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

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