Set session methods as default for all implementing classes
This commit is contained in:
parent
b392011a7b
commit
0833e00a63
|
@ -7,9 +7,20 @@
|
||||||
* @package WooCommerce/Classes/Abstracts
|
* @package WooCommerce/Classes/Abstracts
|
||||||
* @author WooThemes
|
* @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
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -18,7 +29,7 @@ abstract class WC_Session {
|
||||||
// When leaving or ending page load, store data
|
// When leaving or ending page load, store data
|
||||||
add_action( 'shutdown', array( &$this, 'save_data' ), 20 );
|
add_action( 'shutdown', array( &$this, 'save_data' ), 20 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __get function.
|
* __get function.
|
||||||
*
|
*
|
||||||
|
@ -26,7 +37,9 @@ abstract class WC_Session {
|
||||||
* @param mixed $property
|
* @param mixed $property
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
abstract public function __get( $property );
|
public function __get( $property ) {
|
||||||
|
return isset( $this->_data[ $property ] ) ? $this->_data[ $property ] : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __set function.
|
* __set function.
|
||||||
|
@ -36,7 +49,9 @@ abstract class WC_Session {
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
abstract public function __set( $property, $value );
|
public function __set( $property, $value ) {
|
||||||
|
$this->_data[ $property ] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __isset function.
|
* __isset function.
|
||||||
|
@ -45,7 +60,9 @@ abstract class WC_Session {
|
||||||
* @param mixed $property
|
* @param mixed $property
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
abstract public function __isset( $property );
|
public function __isset( $property ) {
|
||||||
|
return isset( $this->_data[ $property ] );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __unset function.
|
* __unset function.
|
||||||
|
@ -54,13 +71,7 @@ abstract class WC_Session {
|
||||||
* @param mixed $property
|
* @param mixed $property
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
abstract public function __unset( $property );
|
public function __unset( $property ) {
|
||||||
|
unset( $this->_data[ $property ] );
|
||||||
/**
|
}
|
||||||
* save_data function.
|
|
||||||
*
|
|
||||||
* @access public
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
abstract public function save_data();
|
|
||||||
}
|
}
|
|
@ -8,10 +8,7 @@
|
||||||
* @package WooCommerce/Classes
|
* @package WooCommerce/Classes
|
||||||
* @author WooThemes
|
* @author WooThemes
|
||||||
*/
|
*/
|
||||||
class WC_Session_Transients extends WC_Session {
|
class WC_Session_Transients extends WC_Session {
|
||||||
|
|
||||||
/** _data */
|
|
||||||
protected $_data;
|
|
||||||
|
|
||||||
/** customer_id */
|
/** customer_id */
|
||||||
private $_customer_id;
|
private $_customer_id;
|
||||||
|
@ -20,21 +17,20 @@ class WC_Session_Transients extends WC_Session {
|
||||||
private $_cookie;
|
private $_cookie;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the session class. Hooks in methods.
|
* Constructor for the session class.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
$this->_cookie = 'wc_session_cookie_' . COOKIEHASH;
|
$this->_cookie = 'wc_session_cookie_' . COOKIEHASH;
|
||||||
$this->_customer_id = $this->get_customer_id();
|
$this->_customer_id = $this->get_customer_id();
|
||||||
$this->_data = maybe_unserialize( get_transient( 'wc_session_' . $this->_customer_id ) );
|
$this->_data = maybe_unserialize( get_transient( 'wc_session_' . $this->_customer_id ) );
|
||||||
|
|
||||||
if ( false === $this->_data )
|
if ( false === $this->_data )
|
||||||
$this->_data = array();
|
$this->_data = array();
|
||||||
|
|
||||||
parent::__construct();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,51 +88,6 @@ class WC_Session_Transients extends WC_Session {
|
||||||
|
|
||||||
return $customer_id;
|
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.
|
* save_data function.
|
||||||
|
|
|
@ -303,7 +303,8 @@ class Woocommerce {
|
||||||
$this->query = new WC_Query(); // Query class, handles front-end queries and loops
|
$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
|
// 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
|
// Load messages
|
||||||
$this->load_messages();
|
$this->load_messages();
|
||||||
|
|
Loading…
Reference in New Issue