Subversion Repositories eFlore/Projets.eflore-projets

Rev

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