1 | <?php |
||
24 | class Give_Session { |
||
25 | |||
26 | /** |
||
27 | * Holds our session data |
||
28 | * |
||
29 | * @var array |
||
30 | * @access private |
||
31 | * @since 1.0 |
||
32 | */ |
||
33 | private $session; |
||
34 | |||
35 | |||
36 | /** |
||
37 | * Whether to use PHP $_SESSION or WP_Session |
||
38 | * |
||
39 | * @var bool |
||
40 | * @access private |
||
41 | * @since 1.0 |
||
42 | */ |
||
43 | private $use_php_sessions = false; |
||
44 | |||
45 | /** |
||
46 | * Expiration Time |
||
47 | * |
||
48 | * @var int |
||
49 | * @access private |
||
50 | * @since 1.0 |
||
51 | */ |
||
52 | private $exp_option = false; |
||
53 | |||
54 | /** |
||
55 | * Session index prefix |
||
56 | * |
||
57 | * @var string |
||
58 | * @access private |
||
59 | * @since 1.0 |
||
60 | */ |
||
61 | private $prefix = ''; |
||
62 | |||
63 | /** |
||
64 | * Get things started |
||
65 | * |
||
66 | * Defines our WP_Session constants, includes the necessary libraries and |
||
67 | * retrieves the WP Session instance |
||
68 | * |
||
69 | * @since 1.0 |
||
70 | */ |
||
71 | 2 | public function __construct() { |
|
114 | |||
115 | /** |
||
116 | * Setup the WP_Session instance |
||
117 | * |
||
118 | * @access public |
||
119 | * @since 1.0 |
||
120 | * @return array $this->session |
||
121 | */ |
||
122 | public function init() { |
||
132 | |||
133 | |||
134 | /** |
||
135 | * Retrieve session ID |
||
136 | * |
||
137 | * @access public |
||
138 | * @since 1.0 |
||
139 | * @return string Session ID |
||
140 | */ |
||
141 | public function get_id() { |
||
144 | |||
145 | |||
146 | /** |
||
147 | * Retrieve a session variable |
||
148 | * |
||
149 | * @access public |
||
150 | * @since 1.0 |
||
151 | * |
||
152 | * @param string $key Session key |
||
153 | * |
||
154 | * @return string Session variable |
||
155 | */ |
||
156 | 9 | public function get( $key ) { |
|
162 | |||
163 | /** |
||
164 | * Set a session variable |
||
165 | * |
||
166 | * @since 1.0 |
||
167 | * |
||
168 | * @param $key $_SESSION key |
||
169 | * @param $value $_SESSION variable |
||
170 | * |
||
171 | * @return mixed Session variable |
||
172 | */ |
||
173 | 8 | public function set( $key, $value ) { |
|
189 | |||
190 | /** |
||
191 | * Set Cookie Variant Time |
||
192 | * |
||
193 | * @description Force the cookie expiration variant time to custom expiration option, less and hour; defaults to 23 hours (set_expiration_variant_time used in WP_Session) |
||
194 | * |
||
195 | * @access public |
||
196 | * @since 1.0 |
||
197 | * |
||
198 | * @return int |
||
199 | */ |
||
200 | public function set_expiration_variant_time() { |
||
204 | |||
205 | /** |
||
206 | * Set the Cookie Expiration |
||
207 | * |
||
208 | * @description Force the cookie expiration time if set, default to 24 hours |
||
209 | * |
||
210 | * @access public |
||
211 | * @since 1.0 |
||
212 | * |
||
213 | * @return int |
||
214 | */ |
||
215 | public function set_expiration_time() { |
||
219 | |||
220 | /** |
||
221 | * Starts a new session if one hasn't started yet. |
||
222 | * |
||
223 | * @return null |
||
224 | * Checks to see if the server supports PHP sessions or if the GIVE_USE_PHP_SESSIONS constant is defined |
||
225 | * |
||
226 | * @access public |
||
227 | * @since 1.0 |
||
228 | * @return bool $ret True if we are using PHP sessions, false otherwise |
||
229 | */ |
||
230 | 4 | public function use_php_sessions() { |
|
269 | |||
270 | /** |
||
271 | * Maybe Start Session |
||
272 | * |
||
273 | * @description Starts a new session if one hasn't started yet. |
||
274 | * @see http://php.net/manual/en/function.session-set-cookie-params.php |
||
275 | */ |
||
276 | public function maybe_start_session() { |
||
287 | |||
288 | |||
289 | /** |
||
290 | * Get Session Expiration |
||
291 | * |
||
292 | * @description Looks at the session cookies and returns the expiration date for this session if applicable |
||
293 | * |
||
294 | */ |
||
295 | public function get_session_expiration() { |
||
308 | |||
309 | } |
||
310 | |||
311 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.