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 |
*
|
|
|
7 |
* @category DEL
|
1793 |
jpm |
8 |
* @package Bibliotheque
|
|
|
9 |
* @version 0.1
|
|
|
10 |
* @author Mathias CHOUET <mathias@tela-botanica.org>
|
|
|
11 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
12 |
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
|
|
|
13 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
|
|
14 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
|
|
15 |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
|
723 |
gduche |
16 |
*/
|
1611 |
jpm |
17 |
//TODO : initialiser tous les objets dans le conteneur
|
|
|
18 |
//TODO : créer un tableau de partage
|
716 |
gduche |
19 |
class Conteneur {
|
1605 |
jpm |
20 |
|
723 |
gduche |
21 |
protected $parametres;
|
1794 |
jpm |
22 |
protected $parametresUrl;
|
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;
|
1794 |
jpm |
31 |
// TODO [2014-05-13 - JPM]: améliorer la gestion des paramètres d'URL fournis au conteneur.
|
|
|
32 |
// Ce conteneur conscidère que les paramètres fournis à son constructeur correspondent aux paramètres de l'URL (GET ou POST)...
|
|
|
33 |
// Ce n'est pas vraiment générique.
|
|
|
34 |
$this->parametresUrl = $this->parametres;
|
716 |
gduche |
35 |
}
|
1605 |
jpm |
36 |
|
723 |
gduche |
37 |
/**
|
1611 |
jpm |
38 |
* Obtenir un paramètre depuis le tableau de paramètres ou depuis le fichier de config
|
|
|
39 |
* @param String $cle le nom du paramètre
|
|
|
40 |
* @return la valeur du paramètre
|
|
|
41 |
* */
|
|
|
42 |
public function getParametre($cle) {
|
|
|
43 |
$valeur = isset($this->parametres[$cle]) ? $this->parametres[$cle] : Config::get($cle);
|
|
|
44 |
return $valeur;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
1694 |
jpm |
48 |
* Obtenir un paramètre depuis le tableau de paramètres ou depuis le fichier de config
|
|
|
49 |
* et le transformer en tableau s'il est de la forme : "cle=valeur,cle=valeur,..."
|
|
|
50 |
* @param String $cle le nom du paramètre
|
|
|
51 |
* @return la valeur du paramètre
|
|
|
52 |
*/
|
|
|
53 |
public function getParametreTableau($cle) {
|
|
|
54 |
$tableau = array();
|
|
|
55 |
$parametre = $this->getParametre($cle);
|
|
|
56 |
if (empty($parametre) === false) {
|
|
|
57 |
$tableauPartiel = explode(',', $parametre);
|
|
|
58 |
foreach ($tableauPartiel as $champ) {
|
|
|
59 |
if (strpos($champ, '=') === false) {
|
|
|
60 |
$tableau[] = trim($champ);
|
|
|
61 |
} else {
|
|
|
62 |
list($cle, $val) = explode('=', $champ);
|
|
|
63 |
$tableau[trim($cle)] = trim($val);
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
return $tableau;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
1611 |
jpm |
71 |
* Enregistrer la valeur d'un paramètre
|
|
|
72 |
* */
|
|
|
73 |
public function setParametre($cle, $valeur) {
|
|
|
74 |
$this->parametres[$cle] = $valeur;
|
|
|
75 |
}
|
|
|
76 |
|
1793 |
jpm |
77 |
//--------------------------------------------------------------------------------------------------------
|
1794 |
jpm |
78 |
// TODO : Supprimer le chargement de configuration présent dans des fichiers séparés.
|
1611 |
jpm |
79 |
/**
|
1794 |
jpm |
80 |
* Charger la configuration depuis un fichier .ini.
|
|
|
81 |
*
|
|
|
82 |
* @param String $fichier le nom du fichier de configuration
|
723 |
gduche |
83 |
* */
|
1794 |
jpm |
84 |
public function chargerConfiguration($fichier) {
|
716 |
gduche |
85 |
$cheminConfigurations = Config::get('chemin_configurations');
|
723 |
gduche |
86 |
if ($cheminConfigurations == null || $cheminConfigurations == '') {
|
1794 |
jpm |
87 |
$message = "Le parametre de configuration 'chemin_configurations' n'est pas défini.";
|
723 |
gduche |
88 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
|
|
89 |
throw new Exception($message, $code);
|
|
|
90 |
}
|
1605 |
jpm |
91 |
|
1794 |
jpm |
92 |
$cheminConfigService = $cheminConfigurations.DS.$fichier;
|
|
|
93 |
if (file_exists($cheminConfigService) === false) {
|
|
|
94 |
$message = "Le fichier de configuration du service est introuvable : $cheminConfigService ";
|
723 |
gduche |
95 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
|
|
96 |
throw new Exception($message, $code);
|
716 |
gduche |
97 |
}
|
1605 |
jpm |
98 |
|
1794 |
jpm |
99 |
Config::charger($cheminConfigService);
|
716 |
gduche |
100 |
}
|
1605 |
jpm |
101 |
|
1793 |
jpm |
102 |
public function getBdd() {
|
|
|
103 |
if (!isset($this->partages['Bdd'])){
|
|
|
104 |
$this->partages['Bdd'] = new Bdd();
|
|
|
105 |
}
|
|
|
106 |
return $this->partages['Bdd'];
|
|
|
107 |
}
|
|
|
108 |
|
1249 |
aurelien |
109 |
public function getRestClient() {
|
1793 |
jpm |
110 |
if (!isset($this->partages['restClient'])){
|
|
|
111 |
$this->partages['restClient'] = new RestClient();
|
1249 |
aurelien |
112 |
}
|
1793 |
jpm |
113 |
return $this->partages['restClient'];
|
1249 |
aurelien |
114 |
}
|
1605 |
jpm |
115 |
|
1794 |
jpm |
116 |
public function getUrl($base) {
|
|
|
117 |
return new Url($base);
|
|
|
118 |
}
|
|
|
119 |
|
1605 |
jpm |
120 |
public function getControleAcces() {
|
1793 |
jpm |
121 |
if (!isset($this->partages['controleAcces'])) {
|
|
|
122 |
$this->partages['controleAcces'] = new ControleAcces($this);
|
1605 |
jpm |
123 |
}
|
1793 |
jpm |
124 |
return $this->partages['controleAcces'];
|
1605 |
jpm |
125 |
}
|
1794 |
jpm |
126 |
|
|
|
127 |
public function getNavigation() {
|
|
|
128 |
if (!isset($this->partages['navigation'])) {
|
|
|
129 |
$this->partages['navigation'] = new Navigation($this, $this->parametresUrl);
|
|
|
130 |
}
|
|
|
131 |
return $this->partages['navigation'];
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
public function getMasque() {
|
|
|
135 |
if (!isset($this->partages['masque'])) {
|
|
|
136 |
$this->partages['masque'] = new Masque($this->getparametre('masques_possibles'), $this->parametresUrl);
|
|
|
137 |
}
|
|
|
138 |
return $this->partages['masque'];
|
|
|
139 |
}
|
|
|
140 |
}
|