Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

glpi / src / plugins / vigilo / Vigilo / VigiloTest.php @ 92b19eed

History | View | Annotate | Download (1.42 KB)

1
<?php
2

    
3
class VigiloTest extends VigiloXml implements ArrayAccess
4
{
5
    protected $name;
6
    protected $args;
7

    
8
    public function __construct($name, array $args = array())
9
    {
10
        $this->name = $name;
11
        $this->args = array();
12

    
13
        foreach ($args as $arg => $value) {
14
            $this[$arg] = $value;
15
        }
16
    }
17

    
18
    public function getNagiosNames()
19
    {
20
        $res = array();
21

    
22
        return $res;
23
    }
24

    
25
    public function offsetExists($offset)
26
    {
27
        $name = is_a($offset, 'VigiloArg') ? $offset->getName() : $offset;
28
        return isset($this->args[$name]);
29
    }
30

    
31
    public function offsetGet($offset)
32
    {
33
        $name = is_a($offset, 'VigiloArg') ? $offset->getName() : $offset;
34
        return isset($this->args[$name]) ? $this->args[$name] : null;
35
    }
36

    
37
    public function offsetSet($offset, $value)
38
    {
39
        if (is_string($offset)) {
40
            $value = new VigiloArg($offset, $value);
41
        }
42

    
43
        if (!is_a($value, 'VigiloArg')) {
44
            throw new \RuntimeException();
45
        }
46

    
47
        return $this->args[$value->getName()] = $value;
48
    }
49

    
50
    public function offsetUnset($offset)
51
    {
52
        $name = is_a($offset, 'VigiloArg') ? $offset->getName() : $offset;
53
        unset($this->args[$name]);
54
    }
55

    
56
    public function __toString()
57
    {
58
        return self::sprintf(
59
            '<test name="%s">%s</test>',
60
            $this->name,
61
            $this->args
62
        );
63
    }
64
}