1 | <?php |
||
30 | class Session extends AbstractHelper |
||
31 | { |
||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $prefix; |
||
36 | |||
37 | /** |
||
38 | * Initialize parent::__constuct calls this after verifying module object. |
||
39 | * |
||
40 | * @return void |
||
41 | */ |
||
42 | public function init() |
||
46 | |||
47 | /** |
||
48 | * Add our module prefix to a name |
||
49 | * |
||
50 | * @param string $name name to prefix |
||
51 | * |
||
52 | * @return string module prefixed name |
||
53 | */ |
||
54 | protected function prefix($name) |
||
60 | |||
61 | /** |
||
62 | * Sets a named session variable respecting our module prefix |
||
63 | * |
||
64 | * @param string $name name of variable |
||
65 | * @param mixed $value value of variable |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | public function set($name, $value) |
||
74 | |||
75 | /** |
||
76 | * Fetch a named session variable respecting our module prefix |
||
77 | * |
||
78 | * @param string $name name of variable |
||
79 | * @param mixed $default default value to return if config $name is not set |
||
80 | * |
||
81 | * @return mixed $value value of session variable or false if not set |
||
82 | */ |
||
83 | public function get($name, $default = false) |
||
92 | |||
93 | /** |
||
94 | * Deletes a named session variable respecting our module prefix |
||
95 | * |
||
96 | * @param string $name name of variable |
||
97 | * |
||
98 | * @return void |
||
99 | */ |
||
100 | public function del($name) |
||
106 | |||
107 | /** |
||
108 | * Delete all session variable starting with our module prefix |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | public function destroy() |
||
121 | } |
||
122 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: