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) {
|
1222 |
jpm |
23 |
$valeur = isset($this->parametres[$cle]) ? $this->parametres[$cle] : null;
|
|
|
24 |
if (is_null($valeur) && $this->etreParametreASection($cle)) {
|
|
|
25 |
$valeur = $this->getParametreAvecSection($cle);
|
|
|
26 |
}
|
1204 |
jpm |
27 |
return $valeur;
|
1222 |
jpm |
28 |
}
|
|
|
29 |
|
|
|
30 |
private function etreParametreASection($cle) {
|
|
|
31 |
return strpos($cle, '.') ? true : false;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
private function getParametreAvecSection($cle) {
|
|
|
35 |
$cleComposee = explode('.', $cle);
|
|
|
36 |
$valeur = $this->parametres;
|
|
|
37 |
foreach ($cleComposee as $cleCourrante) {
|
|
|
38 |
$valeur = isset($valeur[$cleCourrante]) ? $valeur[$cleCourrante] : null;
|
|
|
39 |
}
|
|
|
40 |
return $valeur;
|
1204 |
jpm |
41 |
}
|
|
|
42 |
|
|
|
43 |
public function getParametreTableau($cle) {
|
|
|
44 |
$tableau = array();
|
|
|
45 |
$parametre = $this->getParametre($cle);
|
|
|
46 |
if (empty($parametre) === false) {
|
|
|
47 |
$tableauPartiel = explode(',', $parametre);
|
|
|
48 |
$tableauPartiel = array_map('trim', $tableauPartiel);
|
|
|
49 |
foreach ($tableauPartiel as $champ) {
|
|
|
50 |
if (strpos($champ, '=') === false) {
|
|
|
51 |
$tableau[] = trim($champ);
|
|
|
52 |
} else {
|
|
|
53 |
list($cle, $val) = explode('=', $champ);
|
|
|
54 |
$tableau[trim($cle)] = trim($val);
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
return $tableau;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public function setParametre($cle, $valeur) {
|
|
|
62 |
$this->parametres[$cle] = $valeur;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public function getBdd() {
|
|
|
66 |
if (!isset($this->partages['Bdd'])){
|
|
|
67 |
$this->partages['Bdd'] = new Bdd($this->getParametre('database_cel'));
|
|
|
68 |
}
|
|
|
69 |
return $this->partages['Bdd'];
|
1222 |
jpm |
70 |
}
|
|
|
71 |
|
|
|
72 |
public function getScript() {
|
|
|
73 |
if (!isset($this->partages['Script'])){
|
|
|
74 |
$this->partages['Script'] = new Script();
|
|
|
75 |
}
|
|
|
76 |
return $this->partages['Script'];
|
1204 |
jpm |
77 |
}
|
|
|
78 |
}
|
|
|
79 |
?>
|