Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 207 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 207 Rev 215
Line 4... Line 4...
4
	private $paramsVerif = null;
4
	private $paramsVerif = null;
5
	private $ressourcesVerif = null;
5
	private $ressourcesVerif = null;
6
	private $cheminBase = '';
6
	private $cheminBase = '';
7
	private $cheminConfig = '';
7
	private $cheminConfig = '';
8
	private $cheminBiblio = '';
8
	private $cheminBiblio = '';
-
 
9
	private $serviceGenerique = '';
Line 9... Line 10...
9
 
10
 
10
	public function __construct(Ressources $ressources) {
11
	public function __construct(Ressources $ressources) {
11
		$this->ressources = $ressources;
12
		$this->ressources = $ressources;
Line 29... Line 30...
29
 
30
 
30
	public function setRessourcesVerif($ressourcesVerificateur) {
31
	public function setRessourcesVerif($ressourcesVerificateur) {
31
		$this->ressourcesVerif = $ressourcesVerificateur;
32
		$this->ressourcesVerif = $ressourcesVerificateur;
Line -... Line 33...
-
 
33
	}
-
 
34
 
-
 
35
	public function setServiceGenerique($generique) {
-
 
36
		$this->serviceGenerique = $generique;
32
	}
37
	}
33
 
38
 
34
	public function initialiser() {
39
	public function initialiser() {
35
		$this->chargerConfig();
40
		$this->chargerConfig();
36
		// php5.3 : Enregistrement en première position des autoload de la méthode gérant les classes des services
41
		// php5.3 : Enregistrement en première position des autoload de la méthode gérant les classes des services
Line 42... Line 47...
42
	}
47
	}
Line 43... Line 48...
43
 
48
 
44
	private function chargerConfig() {
49
	private function chargerConfig() {
45
		$projet = $this->getNom();
50
		$projet = $this->getNom();
46
		$chemin = $this->cheminConfig."config_$projet.ini";
-
 
47
 
51
		$chemin = $this->cheminConfig."config_$projet.ini";
48
		Config::charger($chemin);
52
		Config::charger($chemin);
Line 49... Line 53...
49
	}
53
	}
50
 
54
 
51
	public function getNom() {
55
	public function getNom() {
Line -... Line 56...
-
 
56
		return $this->ressources->getProjetNom();
-
 
57
	}
-
 
58
 
-
 
59
	public function getClasse() {
52
		return $this->ressources->getProjetNom();
60
		return $this->ressources->getServiceClasse().ucfirst($this->getNom());
53
	}
61
	}
54
 
62
 
55
	private function chargerClasseProjet($classe) {
63
	private function chargerClasseProjet($classe) {
Line 56... Line 64...
56
		if (class_exists($classe)) {
64
		if (class_exists($classe)) {
57
			return null;
65
			return null;
58
		}
66
		}
59
 
67
 
-
 
68
		$chemins = array();
60
		$chemins = array();
69
		$chemins[] = $this->cheminBase.$this->getNom().DS;
61
		$chemins[] = $this->cheminBase.$this->getNom().DS;
70
		$chemins[] = $this->cheminBase.'commun'.DS;
62
		$chemins[] = $this->cheminBase.'commun'.DS;
71
		$chemins[] = $this->cheminBiblio;
Line 63... Line 72...
63
		$chemins[] = $this->cheminBiblio;
72
		$chemins[] = $this->cheminBiblio.'generique'.DS;
Line 71... Line 80...
71
				require_once $chemin;
80
				require_once $chemin;
72
			}
81
			}
73
		}
82
		}
74
	}
83
	}
Line 75... Line -...
75
 
-
 
76
	public function getServiceClasseNom() {
-
 
77
		$classeNom = '';
-
 
78
		if ($this->ressources->getNombre() == 2) {
-
 
79
			if ($this->ressources->getServiceNom() == 'noms') {
-
 
80
				$classeNom = 'NomsListe';
-
 
81
			} else if ($this->ressources->getServiceNom() == 'taxons') {
-
 
82
				$classeNom = 'TaxonsListe';
-
 
83
			}
-
 
84
 
-
 
85
		} else if ($this->ressources->getNombre() == 3) {
-
 
86
			$position3 = $this->ressources->getParPosition(2);
-
 
87
			if ($this->ressources->etreId($position3)) {
-
 
88
				if ($this->ressources->getServiceNom() == 'noms') {
-
 
89
					$classeNom = 'NomDetails';
-
 
90
				} else if ($this->ressources->getServiceNom() == 'taxons') {
-
 
91
					$classeNom = 'TaxonDetails';
-
 
92
				}
-
 
93
			}
-
 
94
		} else if ($this->ressources->getNombre() == 4) {
-
 
95
			$position3 = $this->ressources->getParPosition(2);
-
 
96
			$position4 = $this->ressources->getParPosition(3);
-
 
97
			if ($this->ressources->etreStats($position3)) {
-
 
98
				if ($this->ressources->etreTypeDeStats($position4)) {
-
 
99
					$classeNom = 'NomsStats'.ucfirst($position4);
-
 
100
				}
-
 
101
			} else if ($this->ressources->etreId($position3)) {
-
 
102
				if ($this->ressources->etreRelations($position4)) {
-
 
103
					$classeNom = 'NomRelations';
-
 
104
				}
-
 
105
			}
-
 
106
		} else if ($this->ressources->getNombre() == 5) {
-
 
107
			$position3 = $this->ressources->getParPosition(2);
-
 
108
			$position4 = $this->ressources->getParPosition(3);
-
 
109
			$position5 = $this->ressources->getParPosition(4);
-
 
110
			if ($this->ressources->etreId($position3)) {
-
 
111
				if ($this->ressources->etreRelations($position4)) {
-
 
112
					if ($this->ressources->etreTypeDeRelations($position5)) {
-
 
113
						$classeNom = 'NomRelations'.ucfirst($position5);
-
 
114
					}
-
 
115
				}
-
 
116
			}
-
 
117
		}
-
 
118
		$classeNomProjet = $classeNom.'Generique';//.ucfirst($this->getNom());
-
 
119
		return $classeNomProjet;
-
 
120
	}
-
 
121
 
84
 
122
	public function verifier() {
85
	public function verifier() {
123
		$this->paramsVerif->verifier();
86
		$this->paramsVerif->verifier();
124
		$this->ressourcesVerif->verifier();
87
		$this->ressourcesVerif->verifier();
125
		$this->verifierExistanceServiceClasse();
88
		$this->verifierExistanceServiceClasse();
Line 126... Line 89...
126
	}
89
	}
-
 
90
 
127
 
91
	private function verifierExistanceServiceClasse() {
-
 
92
		$classe = $this->getClasse();
-
 
93
		$existe = $this->verifierExistanceClasseDuProjet($classe);
128
	private function verifierExistanceServiceClasse() {
94
 
129
		$service = $this->ressources->getServiceNom();
95
		if ($existe === false) {
-
 
96
			$service = $this->ressources->getServiceNom();
-
 
97
			$projet = $this->getNom();
-
 
98
			$message = "La classe du service demandé '$service' n'existe pas dans le projet '$projet' !";
-
 
99
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
-
 
100
			throw new Exception($message, $code);
Line -... Line 101...
-
 
101
		}
130
		$classe = $this->getServiceClasseNom();
102
	}
131
		$projet = $this->getNom();
103
 
132
 
104
	private function verifierExistanceClasseDuProjet($classe) {
Line 133... Line 105...
133
		$chemins = array();
105
		$chemins = array();
134
		$chemins[] = $this->cheminBase.$projet.DS.$classe.'.php';
106
		$chemins[] = $this->cheminBase.$this->getNom().DS.$classe.'.php';
135
		$chemins[] = $this->cheminBase.'commun'.DS.$classe.'.php';
107
		$chemins[] = $this->cheminBase.'commun'.DS.$classe.'.php';
136
 
108
 
137
		$existe = false;
109
		$existe = false;
138
		foreach ($chemins as $chemin) {
110
		foreach ($chemins as $chemin) {
139
			if (file_exists($chemin)) {
111
			if (file_exists($chemin)) {
-
 
112
				$existe = true;
-
 
113
				break;
-
 
114
			}
140
				$existe = true;
115
		}
141
				break;
116
		return $existe;
142
			}
117
	}
143
		}
118
 
144
		if ($existe === false) {
119
	public function consulter() {
145
			$message = "La classe '$classe' du service demandé '$service' n'existe pas dans le projet '$projet' !";
120
		$serviceNom = $this->getClasse();
Line 146... Line 121...
146
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
121
		$service = new $serviceNom($this->serviceGenerique);
147
			throw new Exception($message, $code);
122
		$retour = $service->consulter();
148
		}
123
		return $retour;