Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

glpi / src / plugins / vigilo / Vigilo / VigiloDepends.php @ f1634ea8

History | View | Annotate | Download (1.87 KB)

1 92b19eed Francois POIROTTE
<?php
2
3
class VigiloDepends extends VigiloXml
4
{
5
    protected $host;
6
    protected $service;
7 ea2027b6 Francois POIROTTE
    protected $weight;
8
    protected $warningWeight;
9 92b19eed Francois POIROTTE
10 ea2027b6 Francois POIROTTE
    public function __construct($host = null, $service = null, $weight = 1, $warningWeight = null)
11 92b19eed Francois POIROTTE
    {
12 0548a1f2 Francois POIROTTE
        /* GLPI signale parfois l'absence de valeur via des chaînes vides,
13
           plutôt qu'en utilisant la constante null. */
14
        if ('' === $host) {
15
            $host = null;
16
        }
17
        if ('' === $service) {
18
            $service = null;
19 92b19eed Francois POIROTTE
        }
20
21 0548a1f2 Francois POIROTTE
        if (null === $host && null === $service) {
22 92b19eed Francois POIROTTE
            throw new Exception('Invalid dependency');
23
        }
24
25 ea2027b6 Francois POIROTTE
        if ((null !== $host && !is_string($host)) ||
26
            (null !== $service && !is_string($service))) {
27
            throw new Exception('Invalid dependency');
28
        }
29
30 0548a1f2 Francois POIROTTE
        if (null === $service && null !== $warningWeight) {
31 ea2027b6 Francois POIROTTE
            // L'état "warning" n'existe pas pour les hôtes.
32
            throw new Exception('Invalid dependency');
33
        }
34
35
        if (null === $warningWeight) {
36
            $warningWeight = $weight;
37
        }
38
39
        $this->host             = $host;
40
        $this->service          = $service;
41
        $this->weight           = (int) $weight;
42
        $this->warningWeight    = (int) $warningWeight;
43 92b19eed Francois POIROTTE
    }
44
45
    public function __toString()
46
    {
47
        if (null === $this->host) {
48 ea2027b6 Francois POIROTTE
            return  "<depends service=\"{$this->service}\" " .
49
                    "weight=\"{$this->weight}\" " .
50
                    "warning_weight=\"{$this->warningWeight}\"/>";
51 92b19eed Francois POIROTTE
        }
52
53
        if (null === $this->service) {
54 ea2027b6 Francois POIROTTE
            return "<depends host=\"{$this->host}\" weight=\"{$this->weight}\"/>";
55 92b19eed Francois POIROTTE
        }
56
57 ea2027b6 Francois POIROTTE
        return  "<depends host=\"{$this->host}\" " .
58
                "service=\"{$this->service}\" " .
59
                "weight=\"{$this->weight}\" " .
60
                "warning_weight=\"{$this->warningWeight}\"/>";
61 92b19eed Francois POIROTTE
    }
62
}