Skip to content

Commit

Permalink
Extracting the CakeSessionHandlerInterface into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 7, 2012
1 parent e5c312f commit 399c293
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 59 deletions.
60 changes: 1 addition & 59 deletions lib/Cake/Model/Datasource/CakeSession.php
Expand Up @@ -682,63 +682,5 @@ protected static function _setError($errorNumber, $errorMessage) {
}
}


/**
* Interface for Session handlers. Custom session handler classes should implement
* this interface as it allows CakeSession know how to map methods to session_set_save_handler()
*
* @package Cake.Model.Datasource
*/
interface CakeSessionHandlerInterface {
/**
* Method called on open of a session.
*
* @return boolean Success
*/
public function open();

/**
* Method called on close of a session.
*
* @return boolean Success
*/
public function close();

/**
* Method used to read from a session.
*
* @param mixed $id The key of the value to read
* @return mixed The value of the key or false if it does not exist
*/
public function read($id);

/**
* Helper function called on write for sessions.
*
* @param integer $id ID that uniquely identifies session in database
* @param mixed $data The value of the data to be saved.
* @return boolean True for successful write, false otherwise.
*/
public function write($id, $data);

/**
* Method called on the destruction of a session.
*
* @param integer $id ID that uniquely identifies session in database
* @return boolean True for successful delete, false otherwise.
*/
public function destroy($id);

/**
* Run the Garbage collection on the session storage. This method should vacuum all
* expired or dead sessions.
*
* @param integer $expires Timestamp (defaults to current time)
* @return boolean Success
*/
public function gc($expires = null);
}


// Initialize the session
CakeSession::init();
CakeSession::init();
1 change: 1 addition & 0 deletions lib/Cake/Model/Datasource/Session/CacheSession.php
Expand Up @@ -18,6 +18,7 @@
*/

App::uses('Cache', 'Cache');
App::uses('CakeSessionHandlerInterface', 'Model/Datasource/Session');

/**
* CacheSession provides method for saving sessions into a Cache engine. Used with CakeSession
Expand Down
70 changes: 70 additions & 0 deletions lib/Cake/Model/Datasource/Session/CakeSessionHandlerInterface.php
@@ -0,0 +1,70 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Model.Datasource
* @since CakePHP(tm) v 2.1
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

/**
* Interface for Session handlers. Custom session handler classes should implement
* this interface as it allows CakeSession know how to map methods to session_set_save_handler()
*
* @package Cake.Model.Datasource.Session
*/
interface CakeSessionHandlerInterface {
/**
* Method called on open of a session.
*
* @return boolean Success
*/
public function open();

/**
* Method called on close of a session.
*
* @return boolean Success
*/
public function close();

/**
* Method used to read from a session.
*
* @param mixed $id The key of the value to read
* @return mixed The value of the key or false if it does not exist
*/
public function read($id);

/**
* Helper function called on write for sessions.
*
* @param integer $id ID that uniquely identifies session in database
* @param mixed $data The value of the data to be saved.
* @return boolean True for successful write, false otherwise.
*/
public function write($id, $data);

/**
* Method called on the destruction of a session.
*
* @param integer $id ID that uniquely identifies session in database
* @return boolean True for successful delete, false otherwise.
*/
public function destroy($id);

/**
* Run the Garbage collection on the session storage. This method should vacuum all
* expired or dead sessions.
*
* @param integer $expires Timestamp (defaults to current time)
* @return boolean Success
*/
public function gc($expires = null);
}
3 changes: 3 additions & 0 deletions lib/Cake/Model/Datasource/Session/DatabaseSession.php
Expand Up @@ -16,6 +16,9 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

App::uses('CakeSessionHandlerInterface', 'Model/Datasource/Session');

/**
* DatabaseSession provides methods to be used with CakeSession.
*
Expand Down

0 comments on commit 399c293

Please sign in to comment.