Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 216 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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