Subversion Repositories eFlore/Projets.eflore-projets

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
163 jpm 1
<?php
2
class Projet {
3
	private $ressources = null;
4
	private $paramsVerif = null;
5
	private $ressourcesVerif = null;
216 jpm 6
	private $versionVerif = null;
163 jpm 7
	private $cheminBase = '';
8
	private $cheminConfig = '';
9
	private $cheminBiblio = '';
215 jpm 10
	private $serviceGenerique = '';
163 jpm 11
 
12
	public function __construct(Ressources $ressources) {
13
		$this->ressources = $ressources;
14
	}
15
 
16
	public function setCheminBase($chemin) {
17
		$this->cheminBase = $chemin;
18
	}
19
 
20
	public function setCheminConfig($chemin) {
21
		$this->cheminConfig = $chemin;
22
	}
23
 
24
	public function setCheminBiblio($chemin) {
25
		$this->cheminBiblio = $chemin;
26
	}
27
 
28
	public function setParamsVerif($paramsVerificateur) {
29
		$this->paramsVerif = $paramsVerificateur;
30
	}
31
 
216 jpm 32
	public function setVersionVerif($versionVerificateur) {
33
		$this->versionVerif = $versionVerificateur;
34
	}
35
 
163 jpm 36
	public function setRessourcesVerif($ressourcesVerificateur) {
37
		$this->ressourcesVerif = $ressourcesVerificateur;
38
	}
39
 
215 jpm 40
	public function setServiceGenerique($generique) {
41
		$this->serviceGenerique = $generique;
42
	}
43
 
163 jpm 44
	public function initialiser() {
45
		$this->chargerConfig();
46
		// php5.3 : Enregistrement en première position des autoload de la méthode gérant les classes des services
47
		if (phpversion() < 5.3) {
48
			spl_autoload_register(array($this, 'chargerClasseProjet'));
49
		} else {
50
			spl_autoload_register(array($this, 'chargerClasseProjet'), true , true);
51
		}
52
	}
53
 
54
	private function chargerConfig() {
55
		$projet = $this->getNom();
56
		$chemin = $this->cheminConfig."config_$projet.ini";
57
		Config::charger($chemin);
58
	}
59
 
60
	public function getNom() {
61
		return $this->ressources->getProjetNom();
62
	}
63
 
215 jpm 64
	public function getClasse() {
65
		return $this->ressources->getServiceClasse().ucfirst($this->getNom());
66
	}
67
 
163 jpm 68
	private function chargerClasseProjet($classe) {
69
		if (class_exists($classe)) {
70
			return null;
71
		}
72
 
73
		$chemins = array();
74
		$chemins[] = $this->cheminBase.$this->getNom().DS;
75
		$chemins[] = $this->cheminBase.'commun'.DS;
76
		$chemins[] = $this->cheminBiblio;
215 jpm 77
		$chemins[] = $this->cheminBiblio.'generique'.DS;
201 jpm 78
		$chemins[] = $this->cheminBiblio.'interfaces'.DS;
163 jpm 79
		$chemins[] = $this->cheminBiblio.'nom'.DS;
80
		$chemins[] = $this->cheminBiblio.'nom'.DS.'decorateurs'.DS;
81
 
82
		foreach ($chemins as $chemin) {
83
			$chemin = $chemin.$classe.'.php';
84
			if (file_exists($chemin)) {
85
				require_once $chemin;
86
			}
87
		}
88
	}
89
 
90
	public function verifier() {
91
		$this->paramsVerif->verifier();
92
		$this->ressourcesVerif->verifier();
216 jpm 93
		$this->versionVerif->verifier();
163 jpm 94
		$this->verifierExistanceServiceClasse();
95
	}
96
 
97
	private function verifierExistanceServiceClasse() {
215 jpm 98
		$classe = $this->getClasse();
99
		$existe = $this->verifierExistanceClasseDuProjet($classe);
163 jpm 100
 
215 jpm 101
		if ($existe === false) {
102
			$service = $this->ressources->getServiceNom();
103
			$projet = $this->getNom();
104
			$message = "La classe du service demandé '$service' n'existe pas dans le projet '$projet' !";
105
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
106
			throw new Exception($message, $code);
107
		}
108
	}
109
 
110
	private function verifierExistanceClasseDuProjet($classe) {
163 jpm 111
		$chemins = array();
215 jpm 112
		$chemins[] = $this->cheminBase.$this->getNom().DS.$classe.'.php';
163 jpm 113
		$chemins[] = $this->cheminBase.'commun'.DS.$classe.'.php';
114
 
115
		$existe = false;
116
		foreach ($chemins as $chemin) {
117
			if (file_exists($chemin)) {
118
				$existe = true;
119
				break;
120
			}
121
		}
215 jpm 122
		return $existe;
163 jpm 123
	}
124
 
215 jpm 125
	public function consulter() {
126
		$serviceNom = $this->getClasse();
127
		$service = new $serviceNom($this->serviceGenerique);
128
		$retour = $service->consulter();
129
		return $retour;
130
	}
131
 
163 jpm 132
}
133
?>