1 | <?php |
||
19 | final class WP_Session extends Recursive_ArrayAccess { |
||
20 | /** |
||
21 | * ID of the current session. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | public $session_id; |
||
26 | |||
27 | /** |
||
28 | * Unix timestamp when session expires. |
||
29 | * |
||
30 | * @var int |
||
31 | */ |
||
32 | protected $expires; |
||
33 | |||
34 | /** |
||
35 | * Unix timestamp indicating when the expiration time needs to be reset. |
||
36 | * |
||
37 | * @var int |
||
38 | */ |
||
39 | protected $exp_variant; |
||
40 | |||
41 | /** |
||
42 | * Singleton instance. |
||
43 | * |
||
44 | * @var bool|WP_Session |
||
45 | */ |
||
46 | private static $instance = false; |
||
47 | |||
48 | /** |
||
49 | * Retrieve the current session instance. |
||
50 | * |
||
51 | * @param bool $session_id Session ID from which to populate data. |
||
|
|||
52 | * |
||
53 | * @return bool|WP_Session |
||
54 | */ |
||
55 | public static function get_instance() { |
||
62 | |||
63 | /** |
||
64 | * Default constructor. |
||
65 | * Will rebuild the session collection from the given session ID if it exists. Otherwise, will |
||
66 | * create a new session with that ID. |
||
67 | * |
||
68 | * @param $session_id |
||
69 | * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire. |
||
70 | */ |
||
71 | protected function __construct() { |
||
96 | |||
97 | /** |
||
98 | * Set both the expiration time and the expiration variant. |
||
99 | * |
||
100 | * If the current time is below the variant, we don't update the session's expiration time. If it's |
||
101 | * greater than the variant, then we update the expiration time in the database. This prevents |
||
102 | * writing to the database on every page load for active sessions and only updates the expiration |
||
103 | * time if we're nearing when the session actually expires. |
||
104 | * |
||
105 | * By default, the expiration time is set to 30 minutes. |
||
106 | * By default, the expiration variant is set to 24 minutes. |
||
107 | * |
||
108 | * As a result, the session expiration time - at a maximum - will only be written to the database once |
||
109 | * every 24 minutes. After 30 minutes, the session will have been expired. No cookie will be sent by |
||
110 | * the browser, and the old session will be queued for deletion by the garbage collector. |
||
111 | * |
||
112 | * @uses apply_filters Calls `wp_session_expiration_variant` to get the max update window for session data. |
||
113 | * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions. |
||
114 | */ |
||
115 | protected function set_expiration() { |
||
119 | |||
120 | /** |
||
121 | * Set the session cookie |
||
122 | * @uses apply_filters Calls `wp_session_cookie_secure` to set the $secure parameter of setcookie() |
||
123 | * @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie() |
||
124 | */ |
||
125 | protected function set_cookie() { |
||
136 | |||
137 | /** |
||
138 | * Read data from a transient for the current session. |
||
139 | * |
||
140 | * Automatically resets the expiration time for the session transient to some time in the future. |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | protected function read_data() { |
||
149 | |||
150 | /** |
||
151 | * Write the data from the current session to the data storage system. |
||
152 | */ |
||
153 | public function write_data() { |
||
164 | |||
165 | /** |
||
166 | * Output the current container contents as a JSON-encoded string. |
||
167 | * |
||
168 | * @return string |
||
169 | */ |
||
170 | public function json_out() { |
||
173 | |||
174 | /** |
||
175 | * Decodes a JSON string and, if the object is an array, overwrites the session container with its contents. |
||
176 | * |
||
177 | * @param string $data |
||
178 | * |
||
179 | * @return bool |
||
180 | */ |
||
181 | public function json_in( $data ) { |
||
191 | |||
192 | /** |
||
193 | * Regenerate the current session's ID. |
||
194 | * |
||
195 | * @param bool $delete_old Flag whether or not to delete the old session data from the server. |
||
196 | */ |
||
197 | public function regenerate_id( $delete_old = false ) { |
||
206 | |||
207 | /** |
||
208 | * Check if a session has been initialized. |
||
209 | * |
||
210 | * @return bool |
||
211 | */ |
||
212 | public function session_started() { |
||
215 | |||
216 | /** |
||
217 | * Return the read-only cache expiration value. |
||
218 | * |
||
219 | * @return int |
||
220 | */ |
||
221 | public function cache_expiration() { |
||
224 | |||
225 | /** |
||
226 | * Flushes all session variables. |
||
227 | */ |
||
228 | public function reset() { |
||
231 | } |
||
232 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.