1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* KumbiaPHP web & app Framework |
4
|
|
|
* |
5
|
|
|
* LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the new BSD license that is bundled |
8
|
|
|
* with this package in the file LICENSE. |
9
|
|
|
* |
10
|
|
|
* @category Kumbia |
11
|
|
|
* @package Security |
12
|
|
|
* |
13
|
|
|
* @copyright Copyright (c) 2005 - 2020 KumbiaPHP Team (http://www.kumbiaphp.com) |
14
|
|
|
* @license https://github.com/KumbiaPHP/KumbiaPHP/blob/master/LICENSE New BSD License |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Clase para el almacenar valores durante una petición. |
19
|
|
|
* |
20
|
|
|
* Permite almacenar valores durante la ejecución de la aplicación. Implementa el |
21
|
|
|
* patrón de diseño Registry |
22
|
|
|
* |
23
|
|
|
* @category Kumbia |
24
|
|
|
* @package Security |
25
|
|
|
* |
26
|
|
|
*/ |
27
|
|
|
class Registry |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Variable donde se guarda el registro |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
private static $registry = array(); |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Establece un valor del registro |
39
|
|
|
* |
40
|
|
|
* @param string $index |
41
|
|
|
* @param string $value |
42
|
|
|
*/ |
43
|
|
|
public static function set($index, $value) |
44
|
|
|
{ |
45
|
|
|
self::$registry[$index] = $value; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Agrega un valor al registro a uno ya establecido |
50
|
|
|
* |
51
|
|
|
* @param string $index |
52
|
|
|
* @param string $value |
53
|
|
|
*/ |
54
|
|
|
public static function append($index, $value) |
55
|
|
|
{ |
56
|
|
|
self::exist($index); |
57
|
|
|
self::$registry[$index][] = $value; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Agrega un valor al registro al inicio de uno ya establecido |
62
|
|
|
* |
63
|
|
|
* @param string $index |
64
|
|
|
* @param string $value |
65
|
|
|
*/ |
66
|
|
|
public static function prepend($index, $value) |
67
|
|
|
{ |
68
|
|
|
self::exist($index); |
69
|
|
|
array_unshift(self::$registry[$index], $value); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Obtiene un valor del registro |
74
|
|
|
* |
75
|
|
|
* @param string $index |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
|
public static function get($index) |
79
|
|
|
{ |
80
|
|
|
if (isset(self::$registry[$index])) { |
81
|
|
|
return self::$registry[$index]; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Crea un index si no existe |
87
|
|
|
* |
88
|
|
|
* @param string $index |
89
|
|
|
*/ |
90
|
|
|
protected function exist($index) { |
91
|
|
|
if (!isset(self::$registry[$index])) { |
92
|
|
|
self::$registry[$index] = array(); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |