Add data and tostring handling to WC_Data
This commit is contained in:
parent
9ce1a21271
commit
6765967be8
|
@ -15,6 +15,12 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
*/
|
*/
|
||||||
abstract class WC_Data {
|
abstract class WC_Data {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Core data for this object, name value pairs (name + default value).
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_data = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores meta in cache for future reads.
|
* Stores meta in cache for future reads.
|
||||||
* A group must be set to to enable caching.
|
* A group must be set to to enable caching.
|
||||||
|
@ -55,12 +61,6 @@ abstract class WC_Data {
|
||||||
*/
|
*/
|
||||||
abstract public function get_id();
|
abstract public function get_id();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all data for this object.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
abstract public function get_data();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new object in the database.
|
* Creates new object in the database.
|
||||||
*/
|
*/
|
||||||
|
@ -87,6 +87,22 @@ abstract class WC_Data {
|
||||||
*/
|
*/
|
||||||
abstract public function save();
|
abstract public function save();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change data to JSON format.
|
||||||
|
* @return string Data in JSON format.
|
||||||
|
*/
|
||||||
|
public function __toString() {
|
||||||
|
return json_encode( $this->get_data() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all data for this object.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_data() {
|
||||||
|
return array_merge( $this->_data, array( 'meta_data' => $this->get_meta_data() ) );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get All Meta Data
|
* Get All Meta Data
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
|
|
Loading…
Reference in New Issue