glpi / src / plugins / vigilo / Vigilo / VigiloDepends.php @ 22269799
History | View | Annotate | Download (1.71 KB)
1 |
<?php
|
---|---|
2 |
|
3 |
class VigiloDepends extends VigiloXml |
4 |
{ |
5 |
protected $host; |
6 |
protected $service; |
7 |
protected $weight; |
8 |
protected $warningWeight; |
9 |
|
10 |
public function __construct($host = null, $service = null, $weight = 1, $warningWeight = null) |
11 |
{ |
12 |
if (null === $host && null === $service) { |
13 |
throw new Exception('Invalid dependency'); |
14 |
} |
15 |
|
16 |
if ('' === $host || '' === $service) { |
17 |
throw new Exception('Invalid dependency'); |
18 |
} |
19 |
|
20 |
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 |
} |
39 |
|
40 |
public function __toString() |
41 |
{ |
42 |
if (null === $this->host) { |
43 |
return "<depends service=\"{$this->service}\" " . |
44 |
"weight=\"{$this->weight}\" " .
|
45 |
"warning_weight=\"{$this->warningWeight}\"/>";
|
46 |
} |
47 |
|
48 |
if (null === $this->service) { |
49 |
return "<depends host=\"{$this->host}\" weight=\"{$this->weight}\"/>"; |
50 |
} |
51 |
|
52 |
return "<depends host=\"{$this->host}\" " . |
53 |
"service=\"{$this->service}\" " .
|
54 |
"weight=\"{$this->weight}\" " .
|
55 |
"warning_weight=\"{$this->warningWeight}\"/>";
|
56 |
} |
57 |
} |