Skip to content

Commit

Permalink
CakeSession improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Jun 18, 2013
1 parent 111bfa4 commit 1b19439
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions lib/Cake/Model/Datasource/CakeSession.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public static function started() {
* @return boolean True if variable is there * @return boolean True if variable is there
*/ */
public static function check($name = null) { public static function check($name = null) {
if (!self::started() && !self::start()) { if (!self::start()) {
return false; return false;
} }
if (empty($name)) { if (empty($name)) {
Expand All @@ -223,9 +223,17 @@ public static function check($name = null) {
} }


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


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


/** /**
* Get / Set the userAgent * Get / Set the user agent
* *
* @param string $userAgent Set the userAgent * @param string $userAgent Set the user agent
* @return void * @return string Current user agent
*/ */
public static function userAgent($userAgent = null) { public static function userAgent($userAgent = null) {
if ($userAgent) { if ($userAgent) {
Expand All @@ -355,7 +363,7 @@ public static function userAgent($userAgent = null) {
* @return mixed The value of the session variable * @return mixed The value of the session variable
*/ */
public static function read($name = null) { public static function read($name = null) {
if (!self::started() && !self::start()) { if (!self::start()) {
return false; return false;
} }
if (is_null($name)) { if (is_null($name)) {
Expand Down Expand Up @@ -393,7 +401,7 @@ protected static function _returnSessionVars() {
* @return boolean True if the write was successful, false if the write failed * @return boolean True if the write was successful, false if the write failed
*/ */
public static function write($name, $value = null) { public static function write($name, $value = null) {
if (!self::started() && !self::start()) { if (!self::start()) {
return false; return false;
} }
if (empty($name)) { if (empty($name)) {
Expand All @@ -418,9 +426,7 @@ public static function write($name, $value = null) {
* @return void * @return void
*/ */
public static function destroy() { public static function destroy() {
if (!self::started()) { self::start();
self::start();
}
session_destroy(); session_destroy();
self::clear(); self::clear();
} }
Expand Down Expand Up @@ -620,7 +626,7 @@ protected static function _startSession() {
* @return void * @return void
*/ */
protected static function _checkValid() { protected static function _checkValid() {
if (!self::started() && !self::start()) { if (!self::start()) {
self::$valid = false; self::$valid = false;
return false; return false;
} }
Expand Down

0 comments on commit 1b19439

Please sign in to comment.