216 |
jpm |
1 |
<?php
|
|
|
2 |
class VersionVerificateur {
|
|
|
3 |
|
|
|
4 |
private $ressources = null;
|
|
|
5 |
private $parametres = null;
|
|
|
6 |
private $versions = null;
|
|
|
7 |
|
|
|
8 |
public function __construct(Ressources $ressources, Parametres $parametres, Versions $versions) {
|
|
|
9 |
$this->ressources = $ressources;
|
|
|
10 |
$this->parametres = $parametres;
|
|
|
11 |
$this->versions = $versions;
|
|
|
12 |
}
|
|
|
13 |
|
|
|
14 |
public function verifier() {
|
|
|
15 |
$this->verifierDispoMultiProjetPourService();
|
|
|
16 |
$this->verifierExistance();
|
|
|
17 |
}
|
|
|
18 |
|
|
|
19 |
private function verifierDispoMultiProjetPourService() {
|
|
|
20 |
$servicesMultiProjet = array('NomDetails');
|
|
|
21 |
$classeService = $this->ressources->getServiceClasse();
|
|
|
22 |
$versionDemandee = $this->parametres->get('version.projet');
|
|
|
23 |
if ($versionDemandee == '*' && in_array($classeService, $servicesMultiProjet) === false) {
|
|
|
24 |
$message = "L'affichage de plusieurs versions ne fonctionne que pour les ressources de type /ressources/#id";
|
|
|
25 |
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
|
|
|
26 |
throw new Exception($message, $code);
|
|
|
27 |
}
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
private function verifierExistance() {
|
|
|
31 |
$versionDemandee = $this->parametres->get('version.projet');
|
|
|
32 |
$versionTrouvee = $this->versions->getVersions();
|
|
|
33 |
if (is_numeric($versionDemandee)) {
|
|
|
34 |
if (count($versionTrouvee) == 0) {
|
|
|
35 |
$projet = $this->ressources->getProjetNom();
|
|
|
36 |
$message = "La version '$versionDemandee' n'est pas disponible pour le projet '$projet' !";
|
|
|
37 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
38 |
throw new Exception($message, $code);
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
}
|
|
|
43 |
}
|
|
|
44 |
?>
|