Initializing CakeSession class only when required, mixing procedural code with class definitions is not good

This commit is contained in:
Jose Lorenzo Rodriguez 2012-01-07 18:31:50 -04:30
parent 399c293b77
commit 7b586369e0

View file

@ -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 @@ class CakeSession {
if (self::started()) {
return true;
}
CakeSession::init();
$id = self::id();
session_write_close();
self::_configureSession();
@ -342,6 +342,9 @@ class CakeSession {
if ($userAgent) {
self::$_userAgent = $userAgent;
}
if (empty(self::$_userAgent)) {
CakeSession::init(self::$path);
}
return self::$_userAgent;
}
@ -680,7 +683,4 @@ class CakeSession {
self::$error[$errorNumber] = $errorMessage;
self::$lastError = $errorNumber;
}
}
// Initialize the session
CakeSession::init();
}