Subversion Repositories eFlore/Applications.del

Rev

Rev 1931 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
716 gduche 1
<?php
1794 jpm 2
// declare(encoding='UTF-8');
716 gduche 3
/**
1793 jpm 4
 * Le conteneur encapsule l'instanciation des classes ainsi que la récupération des paramètres depuis l'url ou
723 gduche 5
 * les fichiers de configuration
1605 jpm 6
 *
1815 jpm 7
 * @category  DEL
8
 * @package   Services
9
 * @package   Bibliotheque
10
 * @version   0.1
11
 * @author    Mathias CHOUET <mathias@tela-botanica.org>
12
 * @author    Jean-Pascal MILCENT <jpm@tela-botanica.org>
13
 * @author    Aurelien PERONNET <aurelien@tela-botanica.org>
14
 * @license   GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license   CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
1793 jpm 16
 * @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
723 gduche 17
 */
1611 jpm 18
//TODO : initialiser tous les objets dans le conteneur
19
//TODO : créer un tableau de partage
716 gduche 20
class Conteneur {
1605 jpm 21
 
723 gduche 22
	protected $parametres;
1793 jpm 23
	protected $partages = array();
1605 jpm 24
 
723 gduche 25
	/**
26
	 * Constructeur de la classe
27
	 * @param Array $parametres (optionnel) les paramètres additionnels à ajouter à ceux des fichiers de config
28
	 * */
716 gduche 29
	public function __construct(array $parametres = null) {
30
		$this->parametres = is_null($parametres) ? array() : $parametres;
31
	}
1605 jpm 32
 
723 gduche 33
	/**
1611 jpm 34
	 * Obtenir un paramètre depuis le tableau de paramètres ou depuis le fichier de config
35
	 * @param String $cle le nom du paramètre
36
	 * @return la valeur du paramètre
37
	 * */
38
	public function getParametre($cle) {
39
		$valeur = isset($this->parametres[$cle]) ? $this->parametres[$cle] : Config::get($cle);
40
		return $valeur;
41
	}
42
 
43
	/**
1694 jpm 44
	 * Obtenir un paramètre depuis le tableau de paramètres ou depuis le fichier de config
45
	 * et le transformer en tableau s'il est de la forme : "cle=valeur,cle=valeur,..."
46
	 * @param String $cle le nom du paramètre
47
	 * @return la valeur du paramètre
48
	 */
49
	public function getParametreTableau($cle) {
50
		$tableau = array();
51
		$parametre = $this->getParametre($cle);
52
		if (empty($parametre) === false) {
53
			$tableauPartiel = explode(',', $parametre);
54
			foreach ($tableauPartiel as $champ) {
55
				if (strpos($champ, '=') === false) {
56
					$tableau[] = trim($champ);
57
				} else {
58
					list($cle, $val) = explode('=', $champ);
59
					$tableau[trim($cle)] = trim($val);
60
				}
61
			}
62
		}
63
		return $tableau;
64
	}
65
 
66
	/**
1611 jpm 67
	 * Enregistrer la valeur d'un paramètre
68
	 * */
69
	public function setParametre($cle, $valeur) {
70
		$this->parametres[$cle] = $valeur;
71
	}
72
 
1793 jpm 73
	//--------------------------------------------------------------------------------------------------------
1794 jpm 74
	// TODO : Supprimer le chargement de configuration présent dans des fichiers séparés.
1611 jpm 75
	/**
1794 jpm 76
	 * Charger la configuration depuis un fichier .ini.
77
	 *
78
	 * @param String $fichier le nom du fichier de configuration
723 gduche 79
	 * */
1794 jpm 80
	public function chargerConfiguration($fichier) {
716 gduche 81
		$cheminConfigurations = Config::get('chemin_configurations');
723 gduche 82
		if ($cheminConfigurations == null || $cheminConfigurations == '') {
1794 jpm 83
			$message = "Le parametre de configuration 'chemin_configurations' n'est pas défini.";
723 gduche 84
			$code = RestServeur::HTTP_CODE_ERREUR;
85
			throw new Exception($message, $code);
86
		}
1605 jpm 87
 
1795 jpm 88
		$cheminConfigService = $cheminConfigurations.$fichier;
1794 jpm 89
		if (file_exists($cheminConfigService) === false) {
1795 jpm 90
			$nomClasse = get_class($this);
91
			$message = "Classe $nomClasse : le fichier de configuration du service est introuvable : $cheminConfigService ";
723 gduche 92
			$code = RestServeur::HTTP_CODE_ERREUR;
93
			throw new Exception($message, $code);
716 gduche 94
		}
1605 jpm 95
 
1794 jpm 96
		Config::charger($cheminConfigService);
716 gduche 97
	}
1605 jpm 98
 
1793 jpm 99
	public function getBdd() {
100
		if (!isset($this->partages['Bdd'])){
101
			$this->partages['Bdd'] = new Bdd();
102
		}
103
		return $this->partages['Bdd'];
104
	}
105
 
1249 aurelien 106
	public function getRestClient() {
1793 jpm 107
		if (!isset($this->partages['restClient'])){
108
			$this->partages['restClient'] = new RestClient();
1249 aurelien 109
		}
1793 jpm 110
		return $this->partages['restClient'];
1249 aurelien 111
	}
1605 jpm 112
 
1794 jpm 113
	public function getUrl($base) {
114
		return new Url($base);
115
	}
116
 
1605 jpm 117
	public function getControleAcces() {
1793 jpm 118
		if (!isset($this->partages['controleAcces'])) {
119
			$this->partages['controleAcces'] = new ControleAcces($this);
1605 jpm 120
		}
1793 jpm 121
		return $this->partages['controleAcces'];
1605 jpm 122
	}
1794 jpm 123
 
124
	public function getNavigation() {
125
		if (!isset($this->partages['navigation'])) {
1806 jpm 126
			$this->partages['navigation'] = new Navigation($this);
1794 jpm 127
		}
128
		return $this->partages['navigation'];
129
	}
130
 
1795 jpm 131
	public function getContexte() {
132
		if (!isset($this->partages['contexte'])) {
133
			$this->partages['contexte'] = new Contexte($this, $_SERVER, $_GET, $_POST, $_SESSION, $_COOKIE);
134
		}
135
		return $this->partages['contexte'];
136
	}
137
 
138
	public function getUtilisateur() {
139
		if (!isset($this->partages['utilisateur'])) {
140
			$this->partages['utilisateur'] = new GestionUtilisateur($this);
141
		}
142
		return $this->partages['utilisateur'];
143
	}
1821 jpm 144
 
145
	public function getSyndicationOutils() {
146
		if (!isset($this->partages['syndicationOutils'])) {
147
			$this->partages['syndicationOutils'] = new SyndicationOutils($this);
148
		}
149
		return $this->partages['syndicationOutils'];
150
	}
1840 jpm 151
 
152
	public function getParametresFiltrage() {
153
		if (!isset($this->partages['parametresFiltrage'])) {
154
			$this->partages['parametresFiltrage'] = new ParametresFiltrage($this);
155
		}
156
		return $this->partages['parametresFiltrage'];
157
	}
158
 
159
	public function getSql() {
160
		if (!isset($this->partages['sql'])) {
161
			$this->partages['sql'] = new Sql($this);
162
		}
163
		return $this->partages['sql'];
164
	}
1931 aurelien 165
 
166
	public function getSquelettePhp() {
167
		if (!isset($this->partages['SquelettePhp'])) {
168
			$this->partages['SquelettePhp'] = new SquelettePhp();
169
		}
170
		return $this->partages['SquelettePhp'];
171
	}
172
 
173
	public function getMessagerie() {
174
		if (!isset($this->partages['Messagerie'])) {
175
			$this->partages['Messagerie'] = new TelaBotanica\Del\Commun\Messagerie($this);
176
		}
177
		return $this->partages['Messagerie'];
178
	}
1794 jpm 179
}