1204 |
jpm |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Le conteneur encapsule les classes et les paramètres de config.
|
|
|
4 |
* Il gère leur instanciation, ainsi que la récupération des paramètres depuis les fichiers de configuration.
|
|
|
5 |
*
|
|
|
6 |
* @category php 5.2
|
|
|
7 |
* @package cel
|
|
|
8 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
9 |
* @copyright Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
|
|
|
10 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
11 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
|
|
12 |
* @version $Id$
|
|
|
13 |
*/
|
|
|
14 |
class Conteneur {
|
|
|
15 |
protected $parametres = array();
|
|
|
16 |
protected $partages = array();
|
|
|
17 |
|
|
|
18 |
public function __construct(array $parametres = null) {
|
|
|
19 |
$this->parametres = is_null($parametres) ? array() : $parametres;
|
|
|
20 |
}
|
|
|
21 |
|
|
|
22 |
public function getParametre($cle) {
|
|
|
23 |
$valeur = isset($this->parametres[$cle]) ? $this->parametres[$cle] : null;
|
|
|
24 |
return $valeur;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
public function getParametreTableau($cle) {
|
|
|
28 |
$tableau = array();
|
|
|
29 |
$parametre = $this->getParametre($cle);
|
|
|
30 |
if (empty($parametre) === false) {
|
|
|
31 |
$tableauPartiel = explode(',', $parametre);
|
|
|
32 |
$tableauPartiel = array_map('trim', $tableauPartiel);
|
|
|
33 |
foreach ($tableauPartiel as $champ) {
|
|
|
34 |
if (strpos($champ, '=') === false) {
|
|
|
35 |
$tableau[] = trim($champ);
|
|
|
36 |
} else {
|
|
|
37 |
list($cle, $val) = explode('=', $champ);
|
|
|
38 |
$tableau[trim($cle)] = trim($val);
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
}
|
|
|
42 |
return $tableau;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public function setParametre($cle, $valeur) {
|
|
|
46 |
$this->parametres[$cle] = $valeur;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public function getBdd() {
|
|
|
50 |
if (!isset($this->partages['Bdd'])){
|
|
|
51 |
$this->partages['Bdd'] = new Bdd($this->getParametre('database_cel'));
|
|
|
52 |
}
|
|
|
53 |
return $this->partages['Bdd'];
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
?>
|