Subversion Repositories Applications.framework

Rev

Rev 120 | Rev 239 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 120 Rev 224
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 à travers les autres classes.
5
 * C'est un singleton
5
 * C'est un singleton.
-
 
6
 *
-
 
7
 * @category	php 5.2
-
 
8
 * @package	Framework
-
 
9
 * @author		Jean-Pascal Milcent <jmp@tela-botanica.org>
-
 
10
 * @copyright	2009 Tela-Botanica
-
 
11
 * @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
-
 
13
 * @version	SVN: $Id: Registre.php 224 2010-11-10 13:37:37Z jpm $
-
 
14
 * @link		/doc/framework/
6
 *
15
 *
7
* PHP Version 5
-
 
8
*
-
 
9
* @category  Class
-
 
10
* @package   Framework
-
 
11
* @author	Jean-Pascal Milcent <jmp@tela-botanica.org>
-
 
12
* @copyright 2009 Tela-Botanica
-
 
13
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
-
 
14
* @license   http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
-
 
15
* @version   SVN: $$Id: Registre.php 120 2009-09-01 12:21:14Z aurelien $$
-
 
16
* @link	  /doc/framework/
-
 
17
*
-
 
18
*/
16
*/
19
class Registre {
17
class Registre {
20
 
-
 
21
	/**
18
 
22
	 * Tableau associatif stockant les variables
-
 
23
	 */
19
	/** Tableau associatif stockant les variables */
24
	private $stockage = array();
20
	private $stockage = array();
25
	/**
21
	
26
	 * La classe registre se contient elle-même, (pour le pattern singleton)
-
 
27
	 */
22
	/** La classe registre se contient elle-même, (pour le pattern singleton) */
28
	private static $registre;
-
 
29
 
23
	private static $registre;
30
	/**
-
 
31
	 * Constructeur par défaut, privé, car on accède à la classe par le getInstance
24
 
32
	 */
-
 
33
	private function __construct() {
25
	/** Constructeur par défaut, privé, car on accède à la classe par le getInstance */
34
	}
26
	private function __construct() {	}
35
 
27
 
36
	/**
28
	/**
37
	 * Fonction qui renvoie l'instance de classe en assurant son unicité, c'est l'unique méthode qui doit être
29
	 * Fonction qui renvoie l'instance de classe en assurant son unicité, c'est l'unique méthode qui doit être
38
	 * utilisée pour récupérer l'objet Registre
30
	 * utilisée pour récupérer l'objet Registre
39
	 */
31
	 */
40
	public static function getInstance() {
32
	public static function getInstance() {
41
		if (self::$registre instanceof Registre) {
33
		if (self::$registre instanceof Registre) {
42
			return self::$registre;
34
			return self::$registre;
43
		}
35
		}
44
		self::$registre = new Registre;
36
		self::$registre = new Registre;
45
		return self::$registre;
37
		return self::$registre;
46
	}
38
	}
47
 
39
 
48
	/**
40
	/**
49
	 * Ajoute un objet au tableau selon un intitulé donné
41
	 * Ajoute un objet au tableau selon un intitulé donné
50
	 * @param string l'intitulé sous lequel l'objet sera conservé
42
	 * @param string l'intitulé sous lequel l'objet sera conservé
51
	 * @param mixed l'objet à conserver
43
	 * @param mixed l'objet à conserver
52
	 */
44
	 */
53
	public function set($intitule, $objet) {
45
	public function set($intitule, $objet) {
54
		if (is_array($objet) && isset($this->stockage[$intitule])) {
46
		if (is_array($objet) && isset($this->stockage[$intitule])) {
55
			$this->stockage[$intitule] = array_merge((array) $this->stockage[$intitule], (array) $objet);
47
			$this->stockage[$intitule] = array_merge((array) $this->stockage[$intitule], (array) $objet);
56
			$message = "Le tableau $intitule présent dans le registre a été fusionné avec un nouveau tableau de même intitulé !";
48
			$message = "Le tableau $intitule présent dans le registre a été fusionné avec un nouveau tableau de même intitulé !";
57
			trigger_error($message, E_USER_WARNING);
49
			trigger_error($message, E_USER_WARNING);
58
		} else {
50
		} else {
59
			$this->stockage[$intitule] = $objet;
51
			$this->stockage[$intitule] = $objet;
60
		}
52
		}
61
	}
53
	}
62
 
54
 
63
	/**
55
	/**
64
	 * Renvoie l'objet associé à l'intitulé donné en paramètre
56
	 * Renvoie l'objet associé à l'intitulé donné en paramètre
65
	 * @return mixed l'objet associé à l'intitulé ou null s'il n'est pas présent
57
	 * @return mixed l'objet associé à l'intitulé ou null s'il n'est pas présent
66
	 */
58
	 */
67
	public function get($intitule) {
59
	public function get($intitule) {
68
		if (isset($this->stockage[$intitule])) {
60
		if (isset($this->stockage[$intitule])) {
69
			return $this->stockage[$intitule];
61
			return $this->stockage[$intitule];
70
		}
62
		}
71
		return null;
63
		return null;
72
	}
64
	}
73
 
65
 
74
	/**
66
	/**
75
	 * 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é
76
	 */
68
	 */
77
	public function detruire($intitule) {
69
	public function detruire($intitule) {
78
		if (isset($this->stockage[$intitule])) {
70
		if (isset($this->stockage[$intitule])) {
79
			unset($this->stockage[$intitule]);
71
			unset($this->stockage[$intitule]);
80
		}
72
		}
81
	}
73
	}
82
 
74
 
83
	/**
75
	/**
84
	 * Teste si un objet est présent sous un intitulé donné
76
	 * Teste si un objet est présent sous un intitulé donné
85
	 * @return boolean true si un objet associé à cet intitulé est présent, false sinon
77
	 * @return boolean true si un objet associé à cet intitulé est présent, false sinon
86
	 */
78
	 */
87
	public function existe($intitule) {
79
	public function existe($intitule) {
88
		if(isset($this->stockage[$intitule])){
80
		if (isset($this->stockage[$intitule])){
89
			return true;
81
			return true;
90
		}
82
		}
91
		return false;
83
		return false;
92
	}
84
	}
93
}
85
}
94
?>
86
?>