Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 215 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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