| Line 1... |
Line 1... |
| 1 |
<?php
|
1 |
<?php
|
| 2 |
// declare(encoding='UTF-8');
|
2 |
// declare(encoding='UTF-8');
|
| 3 |
/**
|
3 |
/**
|
| 4 |
* Classe registre, qui permet un accès à différentes variables à travers les autres classes.
|
4 |
* Classe Registre, qui permet un accès à différentes variables et paramètres à travers les autres classes.
|
| - |
|
5 |
* C'est un remplaçant à la variable magique $_GLOBALS de Php.
|
| 5 |
* C'est un singleton.
|
6 |
* C'est un singleton.
|
| - |
|
7 |
* Si vous avez besoin de modifier dynamiquement des paramètres de configuration, utiliser le @see Registe, il est fait pour ça.
|
| - |
|
8 |
* Si vous voulez paramètré votre application via le fichier config.ini, utilisez plutôt la classe @see Config.
|
| 6 |
*
|
9 |
*
|
| 7 |
* @category php 5.2
|
10 |
* @category php 5.2
|
| 8 |
* @package Framework
|
11 |
* @package Framework
|
| 9 |
* @author Jean-Pascal Milcent <jmp@tela-botanica.org>
|
12 |
* @author Jean-Pascal MILCENT <jmp@tela-botanica.org>
|
| 10 |
* @copyright 2009 Tela-Botanica
|
13 |
* @copyright Copyright (c) 2009, Tela Botanica (accueil@tela-botanica.org)
|
| 11 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
14 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
| 12 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
15 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
| 13 |
* @version SVN: $Id: Registre.php 224 2010-11-10 13:37:37Z jpm $
|
16 |
* @version $Id: Registre.php 239 2010-11-25 18:04:00Z jpm $
|
| 14 |
* @link /doc/framework/
|
17 |
* @link /doc/framework/
|
| 15 |
*
|
18 |
*
|
| 16 |
*/
|
19 |
*/
|
| 17 |
class Registre {
|
20 |
class Registre {
|
| Line 18... |
Line 21... |
| 18 |
|
21 |
|
| 19 |
/** Tableau associatif stockant les variables */
|
22 |
/** Tableau associatif stockant les variables. */
|
| Line 20... |
Line -... |
| 20 |
private $stockage = array();
|
- |
|
| 21 |
|
- |
|
| 22 |
/** La classe registre se contient elle-même, (pour le pattern singleton) */
|
- |
|
| 23 |
private static $registre;
|
- |
|
| 24 |
|
- |
|
| 25 |
/** Constructeur par défaut, privé, car on accède à la classe par le getInstance */
|
- |
|
| 26 |
private function __construct() { }
|
23 |
private static $stockage = array();
|
| 27 |
|
- |
|
| 28 |
/**
|
- |
|
| 29 |
* Fonction qui renvoie l'instance de classe en assurant son unicité, c'est l'unique méthode qui doit être
|
- |
|
| 30 |
* utilisée pour récupérer l'objet Registre
|
- |
|
| 31 |
*/
|
- |
|
| 32 |
public static function getInstance() {
|
- |
|
| 33 |
if (self::$registre instanceof Registre) {
|
- |
|
| 34 |
return self::$registre;
|
- |
|
| 35 |
}
|
- |
|
| 36 |
self::$registre = new Registre;
|
- |
|
| 37 |
return self::$registre;
|
- |
|
| 38 |
}
|
- |
|
| 39 |
|
24 |
|
| 40 |
/**
|
25 |
/**
|
| 41 |
* Ajoute un objet au tableau selon un intitulé donné
|
26 |
* Ajoute un objet au tableau selon un intitulé donné.
|
| 42 |
* @param string l'intitulé sous lequel l'objet sera conservé
|
27 |
* @param string l'intitulé sous lequel l'objet sera conservé
|
| 43 |
* @param mixed l'objet à conserver
|
28 |
* @param mixed l'objet à conserver
|
| 44 |
*/
|
29 |
*/
|
| 45 |
public function set($intitule, $objet) {
|
30 |
public static function set($intitule, $objet) {
|
| 46 |
if (is_array($objet) && isset($this->stockage[$intitule])) {
|
31 |
if (is_array($objet) && isset(self::$stockage[$intitule])) {
|
| 47 |
$this->stockage[$intitule] = array_merge((array) $this->stockage[$intitule], (array) $objet);
|
32 |
self::$stockage[$intitule] = array_merge((array) self::$stockage[$intitule], (array) $objet);
|
| 48 |
$message = "Le tableau $intitule présent dans le registre a été fusionné avec un nouveau tableau de même intitulé !";
|
33 |
$message = "Le tableau $intitule présent dans le registre a été fusionné avec un nouveau tableau de même intitulé !";
|
| 49 |
trigger_error($message, E_USER_WARNING);
|
34 |
trigger_error($message, E_USER_WARNING);
|
| 50 |
} else {
|
35 |
} else {
|
| 51 |
$this->stockage[$intitule] = $objet;
|
36 |
self::$stockage[$intitule] = $objet;
|
| Line 52... |
Line 37... |
| 52 |
}
|
37 |
}
|
| 53 |
}
|
38 |
}
|
| 54 |
|
39 |
|
| 55 |
/**
|
40 |
/**
|
| 56 |
* Renvoie l'objet associé à l'intitulé donné en paramètre
|
41 |
* Renvoie le contenu associé à l'intitulé donné en paramètre.
|
| 57 |
* @return mixed l'objet associé à l'intitulé ou null s'il n'est pas présent
|
42 |
* @return mixed l'objet associé à l'intitulé ou null s'il n'est pas présent
|
| 58 |
*/
|
- |
|
| 59 |
public function get($intitule) {
|
- |
|
| 60 |
if (isset($this->stockage[$intitule])) {
|
43 |
*/
|
| 61 |
return $this->stockage[$intitule];
|
44 |
public static function get($intitule) {
|
| Line 62... |
Line 45... |
| 62 |
}
|
45 |
$retour = (isset(self::$stockage[$intitule])) ? self::$stockage[$intitule] : null;
|
| 63 |
return null;
|
46 |
return $retour;
|
| - |
|
47 |
}
|
| 64 |
}
|
48 |
|
| 65 |
|
49 |
/**
|
| 66 |
/**
|
50 |
* Détruit l'objet associé à l'intitulé, n'a pas d'effet si il n'y a pas d'objet associé.
|
| 67 |
* Détruit l'objet associé à l'intitulé, n'a pas d'effet si il n'y a pas d'objet associé
|
51 |
* @param string l'intitulé de l'entrée du registre à détruire.
|
| 68 |
*/
|
52 |
*/
|
| 69 |
public function detruire($intitule) {
|
53 |
public static function detruire($intitule) {
|
| Line 70... |
Line 54... |
| 70 |
if (isset($this->stockage[$intitule])) {
|
54 |
if (isset(self::$stockage[$intitule])) {
|
| 71 |
unset($this->stockage[$intitule]);
|
55 |
unset(self::$stockage[$intitule]);
|
| - |
|
56 |
}
|
| 72 |
}
|
57 |
}
|
| 73 |
}
|
58 |
|
| 74 |
|
59 |
/**
|
| 75 |
/**
|
60 |
* Teste si le registre contient une donnée pour un intitulé d'entrée donné.
|
| 76 |
* Teste si un objet est présent sous un intitulé donné
|
61 |
* @param string l'intitulé de l'entrée du registre à tester.
|
| 77 |
* @return boolean true si un objet associé à cet intitulé est présent, false sinon
|
- |
|
| 78 |
*/
|
- |
|
| 79 |
public function existe($intitule) {
|
62 |
* @return boolean true si un objet associé à cet intitulé est présent, false sinon
|
| 80 |
if (isset($this->stockage[$intitule])){
|
63 |
*/
|
| 81 |
return true;
|
64 |
public static function existe($intitule) {
|
| 82 |
}
|
65 |
$retour = (isset(self::$stockage[$intitule])) ? true : false;
|