glpi / src / plugins / vigilo / Vigilo / VigiloDepends.php @ e878cf6c
History | View | Annotate | Download (1.71 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 | if (null === $host && null === $service) { |
||
13 | throw new Exception('Invalid dependency'); |
||
14 | } |
||
15 | |||
16 | ea2027b6 | Francois POIROTTE | if ('' === $host || '' === $service) { |
17 | 92b19eed | Francois POIROTTE | throw new Exception('Invalid dependency'); |
18 | } |
||
19 | |||
20 | ea2027b6 | Francois POIROTTE | if ((null !== $host && !is_string($host)) || |
21 | (null !== $service && !is_string($service))) { |
||
22 | throw new Exception('Invalid dependency'); |
||
23 | } |
||
24 | |||
25 | if (null !== $host && null !== $warningWeight) { |
||
26 | // L'état "warning" n'existe pas pour les hôtes.
|
||
27 | throw new Exception('Invalid dependency'); |
||
28 | } |
||
29 | |||
30 | if (null === $warningWeight) { |
||
31 | $warningWeight = $weight; |
||
32 | } |
||
33 | |||
34 | $this->host = $host; |
||
35 | $this->service = $service; |
||
36 | $this->weight = (int) $weight; |
||
37 | $this->warningWeight = (int) $warningWeight; |
||
38 | 92b19eed | Francois POIROTTE | } |
39 | |||
40 | public function __toString() |
||
41 | { |
||
42 | if (null === $this->host) { |
||
43 | ea2027b6 | Francois POIROTTE | return "<depends service=\"{$this->service}\" " . |
44 | "weight=\"{$this->weight}\" " .
|
||
45 | "warning_weight=\"{$this->warningWeight}\"/>";
|
||
46 | 92b19eed | Francois POIROTTE | } |
47 | |||
48 | if (null === $this->service) { |
||
49 | ea2027b6 | Francois POIROTTE | return "<depends host=\"{$this->host}\" weight=\"{$this->weight}\"/>"; |
50 | 92b19eed | Francois POIROTTE | } |
51 | |||
52 | ea2027b6 | Francois POIROTTE | return "<depends host=\"{$this->host}\" " . |
53 | "service=\"{$this->service}\" " .
|
||
54 | "weight=\"{$this->weight}\" " .
|
||
55 | "warning_weight=\"{$this->warningWeight}\"/>";
|
||
56 | 92b19eed | Francois POIROTTE | } |
57 | } |