| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.4/wp-content/plugins/woocommerce/includes/ |
Upload File : |
<?php
/**
* 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
* SQL updates if nothing changed.
*
* @version 3.2.0
* @package WooCommerce
*/
defined( 'ABSPATH' ) || exit;
/**
* Meta data class.
*/
class WC_Meta_Data implements JsonSerializable {
/**
* Current data for metadata
*
* @since 3.2.0
* @var array
*/
protected $current_data;
/**
* Metadata data
*
* @since 3.2.0
* @var array
*/
protected $data;
/**
* Constructor.
*
* @param array $meta Data to wrap behind this function.
*/
public function __construct( $meta = array() ) {
$this->current_data = $meta;
$this->apply_changes();
}
/**
* When converted to JSON.
*
* @return object|array
*/
#[\ReturnTypeWillChange]
public function jsonSerialize() {
return $this->get_data();
}
/**
* Merge changes with data and clear.
*/
public function apply_changes() {
$this->data = $this->current_data;
}
/**
* Creates or updates a property in the metadata object.
*
* @param string $key Key to set.
* @param mixed $value Value to set.
*/
public function __set( $key, $value ) {
$this->current_data[ $key ] = $value;
}
/**
* Checks if a given key exists in our data. This is called internally
* by `empty` and `isset`.
*
* @param string $key Key to check if set.
*
* @return bool
*/
public function __isset( $key ) {
return array_key_exists( $key, $this->current_data );
}
/**
* Returns the value of any property.
*
* @param string $key Key to get.
* @return mixed Property value or NULL if it does not exists
*/
public function __get( $key ) {
if ( array_key_exists( $key, $this->current_data ) ) {
return $this->current_data[ $key ];
}
return null;
}
/**
* Return data changes only.
*
* @return array
*/
public function get_changes() {
$changes = array();
foreach ( $this->current_data as $id => $value ) {
if ( ! array_key_exists( $id, $this->data ) || $value !== $this->data[ $id ] ) {
$changes[ $id ] = $value;
}
}
return $changes;
}
/**
* Return all data as an array.
*
* @return array
*/
public function get_data() {
return $this->data;
}
}