Skip to content
Browse files

Initializing CakeSession class only when required, mixing procedural …

…code with class definitions is not good
  • Loading branch information...
1 parent 399c293 commit 7b586369e044f1551f4ce0b56c813c6cf9d53d89 @lorenzo lorenzo committed
Showing with 6 additions and 6 deletions.
  1. +6 −6 lib/Cake/Model/Datasource/CakeSession.php
View
12 lib/Cake/Model/Datasource/CakeSession.php
@@ -125,10 +125,9 @@ class CakeSession {
* Constructor.
*
* @param string $base The base path for the Session
- * @param boolean $start Should session be started right now
* @return void
*/
- public static function init($base = null, $start = true) {
+ public static function init($base = null) {
self::$time = time();
$checkAgent = Configure::read('Session.checkAgent');
@@ -181,6 +180,7 @@ public static function start() {
if (self::started()) {
return true;
}
+ CakeSession::init();
$id = self::id();
session_write_close();
self::_configureSession();
@@ -342,6 +342,9 @@ public static function userAgent($userAgent = null) {
if ($userAgent) {
self::$_userAgent = $userAgent;
}
+ if (empty(self::$_userAgent)) {
+ CakeSession::init(self::$path);
+ }
return self::$_userAgent;
}
@@ -680,7 +683,4 @@ protected static function _setError($errorNumber, $errorMessage) {
self::$error[$errorNumber] = $errorMessage;
self::$lastError = $errorNumber;
}
-}
-
-// Initialize the session
-CakeSession::init();
+}

0 comments on commit 7b58636

Please sign in to comment.
Something went wrong with that request. Please try again.