mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Updating session to lazy start after the first time an operation has been performed. This should make controllers that only use sessions on some actions perform better.
This commit is contained in:
parent
9e1c85e627
commit
8eebdffcbb
2 changed files with 22 additions and 4 deletions
|
@ -226,6 +226,9 @@ class CakeSession {
|
|||
* @return boolean True if variable is there
|
||||
*/
|
||||
public static function check($name = null) {
|
||||
if (!self::started() && !self::start()) {
|
||||
return false;
|
||||
}
|
||||
if (empty($name)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -368,12 +371,15 @@ class CakeSession {
|
|||
* @return mixed The value of the session variable
|
||||
*/
|
||||
public static function read($name = null) {
|
||||
if (empty($name)) {
|
||||
if (!self::started() && !self::start()) {
|
||||
return false;
|
||||
}
|
||||
if (is_null($name)) {
|
||||
return self::__returnSessionVars();
|
||||
}
|
||||
if (empty($name)) {
|
||||
return false;
|
||||
}
|
||||
$result = Set::classicExtract($_SESSION, $name);
|
||||
|
||||
if (!is_null($result)) {
|
||||
|
@ -403,6 +409,9 @@ class CakeSession {
|
|||
* @return void
|
||||
*/
|
||||
public static function watch($var) {
|
||||
if (!self::started() && !self::start()) {
|
||||
return false;
|
||||
}
|
||||
if (empty($var)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -418,6 +427,9 @@ class CakeSession {
|
|||
* @return void
|
||||
*/
|
||||
public static function ignore($var) {
|
||||
if (!self::started() && !self::start()) {
|
||||
return false;
|
||||
}
|
||||
if (!in_array($var, self::$watchKeys)) {
|
||||
return;
|
||||
}
|
||||
|
@ -438,6 +450,9 @@ class CakeSession {
|
|||
* @return boolean True if the write was successful, false if the write failed
|
||||
*/
|
||||
public static function write($name, $value = null) {
|
||||
if (!self::started() && !self::start()) {
|
||||
return false;
|
||||
}
|
||||
if (empty($name)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -666,6 +681,10 @@ class CakeSession {
|
|||
* @return void
|
||||
*/
|
||||
protected static function _checkValid() {
|
||||
if (!self::started() && !self::start()) {
|
||||
self::$valid = false;
|
||||
return false;
|
||||
}
|
||||
if (self::read('Config')) {
|
||||
$sessionConfig = Configure::read('Session');
|
||||
|
||||
|
|
|
@ -305,8 +305,8 @@ class CakeSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testId() {
|
||||
$expected = session_id();
|
||||
$result = TestCakeSession::id();
|
||||
$expected = session_id();
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
TestCakeSession::id('MySessionId');
|
||||
|
@ -321,10 +321,9 @@ class CakeSessionTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testStarted() {
|
||||
$this->assertTrue(TestCakeSession::started());
|
||||
|
||||
unset($_SESSION);
|
||||
$_SESSION = null;
|
||||
|
||||
$this->assertFalse(TestCakeSession::started());
|
||||
$this->assertTrue(TestCakeSession::start());
|
||||
$this->assertTrue(TestCakeSession::started());
|
||||
|
|
Loading…
Add table
Reference in a new issue