Subversion Repositories Applications.framework

Rev

Rev 467 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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