Skip to content

Commit

Permalink
Changing return types
Browse files Browse the repository at this point in the history
read now returns empty string instead of false when read method returns an empty value.
write, destroy and gc will return boolean type
  • Loading branch information
phpnut committed Dec 22, 2015
1 parent 776c128 commit dd11c63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
12 changes: 8 additions & 4 deletions lib/Cake/Model/Datasource/Session/CacheSession.php
Expand Up @@ -52,7 +52,11 @@ public function close() {
* @return mixed The value of the key or false if it does not exist
*/
public function read($id) {
return Cache::read($id, Configure::read('Session.handler.config'));
$data = Cache::read($id, Configure::read('Session.handler.config'));
if(empty($data)){
return '';
}
return $data;
}

/**
Expand All @@ -63,7 +67,7 @@ public function read($id) {
* @return bool True for successful write, false otherwise.
*/
public function write($id, $data) {
return Cache::write($id, $data, Configure::read('Session.handler.config'));
return (bool)Cache::write($id, $data, Configure::read('Session.handler.config'));
}

/**
Expand All @@ -73,7 +77,7 @@ public function write($id, $data) {
* @return bool True for successful delete, false otherwise.
*/
public function destroy($id) {
return Cache::delete($id, Configure::read('Session.handler.config'));
return (bool)Cache::delete($id, Configure::read('Session.handler.config'));
}

/**
Expand All @@ -83,7 +87,7 @@ public function destroy($id) {
* @return bool Success
*/
public function gc($expires = null) {
return Cache::gc(Configure::read('Session.handler.config'), $expires);
return (bool)Cache::gc(Configure::read('Session.handler.config'), $expires);
}

}
14 changes: 8 additions & 6 deletions lib/Cake/Model/Datasource/Session/DatabaseSession.php
Expand Up @@ -93,10 +93,10 @@ public function read($id) {
));

if (empty($row[$this->_model->alias]['data'])) {
return false;
return '';
}

return $row[$this->_model->alias]['data'];
return (string)$row[$this->_model->alias]['data'];
}

/**
Expand All @@ -123,9 +123,9 @@ public function write($id, $data) {
'counterCache' => false
);
try {
return $this->_model->save($record, $options);
return (bool)$this->_model->save($record, $options);
} catch (PDOException $e) {
return $this->_model->save($record, $options);
return (bool)$this->_model->save($record, $options);
}
}

Expand All @@ -136,7 +136,8 @@ public function write($id, $data) {
* @return bool True for successful delete, false otherwise.
*/
public function destroy($id) {
return $this->_model->delete($id);
return true;
return (bool)$this->_model->delete($id);
}

/**
Expand All @@ -151,7 +152,8 @@ public function gc($expires = null) {
} else {
$expires = time() - $expires;
}
return $this->_model->deleteAll(array($this->_model->alias . ".expires <" => $expires), false, false);
$this->_model->deleteAll(array($this->_model->alias . ".expires <" => $expires), false, false);
return true;
}

}

0 comments on commit dd11c63

Please sign in to comment.