Skip to content

Commit 1b19439

Browse files
author
euromark
committed
CakeSession improvements
1 parent 111bfa4 commit 1b19439

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

lib/Cake/Model/Datasource/CakeSession.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public static function started() {
213213
* @return boolean True if variable is there
214214
*/
215215
public static function check($name = null) {
216-
if (!self::started() && !self::start()) {
216+
if (!self::start()) {
217217
return false;
218218
}
219219
if (empty($name)) {
@@ -223,9 +223,17 @@ public static function check($name = null) {
223223
}
224224

225225
/**
226-
* Returns the Session id
226+
* Returns the session id.
227+
* Calling this method will not auto start the session. You might have to manually
228+
* assert a started session.
227229
*
228-
* @param string $id
230+
* Passing an id into it, you can also replace the session id if the session
231+
* has not already been started.
232+
* Note that depending on the session handler, not all characters are allowed
233+
* within the session id. For example, the file session handler only allows
234+
* characters in the range a-z A-Z 0-9 , (comma) and - (minus).
235+
*
236+
* @param string $id Id to replace the current session id
229237
* @return string Session id
230238
*/
231239
public static function id($id = null) {
@@ -254,7 +262,7 @@ public static function delete($name) {
254262
}
255263

256264
/**
257-
* Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself
265+
* Used to write new data to _SESSION, since PHP doesn't like us setting the _SESSION var itself.
258266
*
259267
* @param array $old Set of old variables => values
260268
* @param array $new New set of variable => value
@@ -333,10 +341,10 @@ protected static function _validAgentAndTime() {
333341
}
334342

335343
/**
336-
* Get / Set the userAgent
344+
* Get / Set the user agent
337345
*
338-
* @param string $userAgent Set the userAgent
339-
* @return void
346+
* @param string $userAgent Set the user agent
347+
* @return string Current user agent
340348
*/
341349
public static function userAgent($userAgent = null) {
342350
if ($userAgent) {
@@ -355,7 +363,7 @@ public static function userAgent($userAgent = null) {
355363
* @return mixed The value of the session variable
356364
*/
357365
public static function read($name = null) {
358-
if (!self::started() && !self::start()) {
366+
if (!self::start()) {
359367
return false;
360368
}
361369
if (is_null($name)) {
@@ -393,7 +401,7 @@ protected static function _returnSessionVars() {
393401
* @return boolean True if the write was successful, false if the write failed
394402
*/
395403
public static function write($name, $value = null) {
396-
if (!self::started() && !self::start()) {
404+
if (!self::start()) {
397405
return false;
398406
}
399407
if (empty($name)) {
@@ -418,9 +426,7 @@ public static function write($name, $value = null) {
418426
* @return void
419427
*/
420428
public static function destroy() {
421-
if (!self::started()) {
422-
self::start();
423-
}
429+
self::start();
424430
session_destroy();
425431
self::clear();
426432
}
@@ -620,7 +626,7 @@ protected static function _startSession() {
620626
* @return void
621627
*/
622628
protected static function _checkValid() {
623-
if (!self::started() && !self::start()) {
629+
if (!self::start()) {
624630
self::$valid = false;
625631
return false;
626632
}

0 commit comments

Comments
 (0)