Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 843 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
163 jpm 1
<?php
2
class RessourcesVerificateur {
3
 
4
	private $ressources = null;
5
	private $projetsDispo = array();
6
	private $servicesDispo = array();
7
 
8
	public function __construct(Ressources $ressources, Array $projetsDispo, Array $servicesDispo) {
9
		$this->ressources = $ressources;
10
		$this->projetsDispo = $projetsDispo;
11
		$this->servicesDispo = $servicesDispo;
12
	}
13
 
14
	public function verifier() {
15
		$this->verifierPresenceRessources();
16
		$this->verifierPresenceProjet();
17
		$this->verifierPresenceService();
18
	}
19
 
20
	private function verifierPresenceRessources() {
21
		if ($this->ressources->getNombre() == 0) {
22
			$message = "Aucune ressource n'a été indiquée.\n".
23
				"Veuillez indiquer au moins un code de projet et un type de service.";
24
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
25
			throw new Exception($message, $code);
26
		}
27
	}
28
 
29
	private function verifierPresenceProjet() {
30
		$projet = $this->ressources->getProjetNom();
31
		if (in_array($projet, $this->projetsDispo) === false) {
32
			$message = "La ressource '$projet' n'indique pas un projet existant.\n".
33
				"Les projets existant sont :\n".implode(', ', $this->projetsDispo);
34
			$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
35
			throw new Exception($message, $code);
36
		}
37
	}
38
 
39
	private function verifierPresenceService() {
40
		$service = $this->ressources->getServiceNom();
41
		if (in_array($service, $this->servicesDispo) === false) {
42
			$message = "La service demandé '$service' n'est pas disponible pour le projet '{$this->ressources->getProjetNom()}' !\n".
43
				"Les services disponibles sont : ".implode(', ', $this->servicesDispo);
44
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
45
			throw new Exception($message, $code);
46
		}
47
	}
48
 
49
 
50
}
51
?>