This commit is contained in:
Mike Jolley 2017-08-08 15:25:32 +01:00
parent b0f3b5a19d
commit 396faa19d7
1 changed files with 21 additions and 20 deletions

View File

@ -1,43 +1,47 @@
<?php <?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/** /**
* Wraps an array (meta data for now) and tells if there was any changes. * Wraps an array (meta data for now) and tells if there was any changes.
* *
* The main idea behind this class is to avoid doing unneeded * The main idea behind this class is to avoid doing unneeded
* SQL updates if nothing changed. * SQL updates if nothing changed.
* *
* @version 3.0.x * @version 3.2.0
* @package WooCommerce * @package WooCommerce
* @category Class * @category Class
* @author crodas * @author crodas
*/ */
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WC_Meta_Data class.
*/
class WC_Meta_Data { class WC_Meta_Data {
/** /**
* Current data for metadata * Current data for metadata
* *
* @since 3.1.0 * @since 3.2.0
* @var arrray * @var array
*/ */
protected $current_data; protected $current_data;
/** /**
* Metadata data * Metadata data
* *
* @since 3.1.0 * @since 3.2.0
* @var arrray * @var array
*/ */
protected $data; protected $data;
/** /**
* Default constructor * Constructor.
* *
* @param Array meta data to wrap behind this function * @param array $meta Data to wrap behind this function.
*/ */
public function __construct( Array $meta ) { public function __construct( $meta = array() ) {
$this->current_data = $meta; $this->current_data = $meta;
$this->apply_changes(); $this->apply_changes();
} }
@ -52,9 +56,8 @@ class WC_Meta_Data {
/** /**
* Creates or updates a property in the metadata object. * Creates or updates a property in the metadata object.
* *
* @param string $key * @param string $key Key to set.
* @param mixed $value * @param mixed $value Value to set.
*
*/ */
public function __set( $key, $value ) { public function __set( $key, $value ) {
$this->current_data[ $key ] = $value; $this->current_data[ $key ] = $value;
@ -64,7 +67,7 @@ class WC_Meta_Data {
* Checks if a given key exists in our data. This is called internally * Checks if a given key exists in our data. This is called internally
* by `empty` and `isset`. * by `empty` and `isset`.
* *
* @param string $key * @param string $key Key to check if set.
*/ */
public function __isset( $key ) { public function __isset( $key ) {
return array_key_exists( $key, $this->current_data ); return array_key_exists( $key, $this->current_data );
@ -73,8 +76,7 @@ class WC_Meta_Data {
/** /**
* Returns the value of any property. * Returns the value of any property.
* *
* @param string $key * @param string $key Key to get.
*
* @return mixed Property value or NULL if it does not exists * @return mixed Property value or NULL if it does not exists
*/ */
public function __get( $key ) { public function __get( $key ) {
@ -96,7 +98,6 @@ class WC_Meta_Data {
$changes[ $id ] = $value; $changes[ $id ] = $value;
} }
} }
return $changes; return $changes;
} }