Set session methods as default for all implementing classes

This commit is contained in:
Coen Jacobs 2012-09-12 16:21:13 +02:00
parent b392011a7b
commit 0833e00a63
3 changed files with 32 additions and 69 deletions

View File

@ -7,9 +7,20 @@
* @package WooCommerce/Classes/Abstracts
* @author WooThemes
*/
abstract class WC_Session {
abstract class WC_Session {
/** _data */
protected $_data;
/**
* save_data function to be implemented
*
* @access public
* @return void
*/
abstract public function save_data();
/**
* Constructor for the session class. Hooks in methods.
* Constructor for the session classes. Hooks in methods.
*
* @access public
* @return void
@ -18,7 +29,7 @@ abstract class WC_Session {
// When leaving or ending page load, store data
add_action( 'shutdown', array( &$this, 'save_data' ), 20 );
}
/**
* __get function.
*
@ -26,7 +37,9 @@ abstract class WC_Session {
* @param mixed $property
* @return mixed
*/
abstract public function __get( $property );
public function __get( $property ) {
return isset( $this->_data[ $property ] ) ? $this->_data[ $property ] : null;
}
/**
* __set function.
@ -36,7 +49,9 @@ abstract class WC_Session {
* @param mixed $value
* @return void
*/
abstract public function __set( $property, $value );
public function __set( $property, $value ) {
$this->_data[ $property ] = $value;
}
/**
* __isset function.
@ -45,7 +60,9 @@ abstract class WC_Session {
* @param mixed $property
* @return bool
*/
abstract public function __isset( $property );
public function __isset( $property ) {
return isset( $this->_data[ $property ] );
}
/**
* __unset function.
@ -54,13 +71,7 @@ abstract class WC_Session {
* @param mixed $property
* @return void
*/
abstract public function __unset( $property );
/**
* save_data function.
*
* @access public
* @return void
*/
abstract public function save_data();
public function __unset( $property ) {
unset( $this->_data[ $property ] );
}
}

View File

@ -8,10 +8,7 @@
* @package WooCommerce/Classes
* @author WooThemes
*/
class WC_Session_Transients extends WC_Session {
/** _data */
protected $_data;
class WC_Session_Transients extends WC_Session {
/** customer_id */
private $_customer_id;
@ -20,21 +17,20 @@ class WC_Session_Transients extends WC_Session {
private $_cookie;
/**
* Constructor for the session class. Hooks in methods.
* Constructor for the session class.
*
* @access public
* @return void
*/
public function __construct() {
parent::__construct();
$this->_cookie = 'wc_session_cookie_' . COOKIEHASH;
$this->_customer_id = $this->get_customer_id();
$this->_data = maybe_unserialize( get_transient( 'wc_session_' . $this->_customer_id ) );
if ( false === $this->_data )
if ( false === $this->_data )
$this->_data = array();
parent::__construct();
}
/**
@ -92,51 +88,6 @@ class WC_Session_Transients extends WC_Session {
return $customer_id;
}
/**
* __get function.
*
* @access public
* @param mixed $property
* @return mixed
*/
public function __get( $property ) {
return isset( $this->_data[ $property ] ) ? $this->_data[ $property ] : null;
}
/**
* __set function.
*
* @access public
* @param mixed $property
* @param mixed $value
* @return void
*/
public function __set( $property, $value ) {
$this->_data[ $property ] = $value;
}
/**
* __isset function.
*
* @access public
* @param mixed $property
* @return bool
*/
public function __isset( $property ) {
return isset( $this->_data[ $property ] );
}
/**
* __unset function.
*
* @access public
* @param mixed $property
* @return void
*/
public function __unset( $property ) {
unset( $this->_data[ $property ] );
}
/**
* save_data function.

View File

@ -303,7 +303,8 @@ class Woocommerce {
$this->query = new WC_Query(); // Query class, handles front-end queries and loops
// Session class, handles session data for customers - can be overwritten if custom handler is needed
$this->session = apply_filters( 'woocommerce_session_handler', new WC_Session_Transients() );
$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Transients' );
$this->session = new $session_class();
// Load messages
$this->load_messages();