glpi / src / plugins / vigilo / Vigilo / VigiloDepends.php @ 8ef154dd
History | View | Annotate | Download (1.87 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 |
/* 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 |
} |
20 |
|
21 |
if (null === $host && null === $service) { |
22 |
throw new Exception('Invalid dependency'); |
23 |
} |
24 |
|
25 |
if ((null !== $host && !is_string($host)) || |
26 |
(null !== $service && !is_string($service))) { |
27 |
throw new Exception('Invalid dependency'); |
28 |
} |
29 |
|
30 |
if (null === $service && null !== $warningWeight) { |
31 |
// 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 |
} |
44 |
|
45 |
public function __toString() |
46 |
{ |
47 |
if (null === $this->host) { |
48 |
return "<depends service=\"{$this->service}\" " . |
49 |
"weight=\"{$this->weight}\" " .
|
50 |
"warning_weight=\"{$this->warningWeight}\"/>";
|
51 |
} |
52 |
|
53 |
if (null === $this->service) { |
54 |
return "<depends host=\"{$this->host}\" weight=\"{$this->weight}\"/>"; |
55 |
} |
56 |
|
57 |
return "<depends host=\"{$this->host}\" " . |
58 |
"service=\"{$this->service}\" " .
|
59 |
"weight=\"{$this->weight}\" " .
|
60 |
"warning_weight=\"{$this->warningWeight}\"/>";
|
61 |
} |
62 |
} |