PHP 8.0.30
Preview: class-wc-data-store.php Size: 6.59 KB
/home/certprox/template.certproxywizard.com/wp-content/plugins/woocommerce/includes/class-wc-data-store.php

<?php
/**
 * WC Data Store.
 *
 * @package WooCommerce\Classes
 * @since   3.0.0
 * @version 3.0.0
 */

defined( 'ABSPATH' ) || exit;

/**
 * Data store class.
 */
class WC_Data_Store {

	/**
	 * Contains an instance of the data store class that we are working with.
	 *
	 * @var WC_Data_Store
	 */
	private $instance = null;

	/**
	 * Contains an array of default WC supported data stores.
	 * Format of object name => class name.
	 * Example: 'product' => 'WC_Product_Data_Store_CPT'
	 * You can also pass something like product_<type> for product stores and
	 * that type will be used first when available, if a store is requested like
	 * this and doesn't exist, then the store would fall back to 'product'.
	 * Ran through `woocommerce_data_stores`.
	 *
	 * @var array
	 */
	private $stores = array(
		'coupon'                => 'WC_Coupon_Data_Store_CPT',
		'customer'              => 'WC_Customer_Data_Store',
		'customer-download'     => 'WC_Customer_Download_Data_Store',
		'customer-download-log' => 'WC_Customer_Download_Log_Data_Store',
		'customer-session'      => 'WC_Customer_Data_Store_Session',
		'order'                 => 'WC_Order_Data_Store_CPT',
		'order-refund'          => 'WC_Order_Refund_Data_Store_CPT',
		'order-item'            => 'WC_Order_Item_Data_Store',
		'order-item-coupon'     => 'WC_Order_Item_Coupon_Data_Store',
		'order-item-fee'        => 'WC_Order_Item_Fee_Data_Store',
		'order-item-product'    => 'WC_Order_Item_Product_Data_Store',
		'order-item-shipping'   => 'WC_Order_Item_Shipping_Data_Store',
		'order-item-tax'        => 'WC_Order_Item_Tax_Data_Store',
		'payment-token'         => 'WC_Payment_Token_Data_Store',
		'product'               => 'WC_Product_Data_Store_CPT',
		'product-grouped'       => 'WC_Product_Grouped_Data_Store_CPT',
		'product-variable'      => 'WC_Product_Variable_Data_Store_CPT',
		'product-variation'     => 'WC_Product_Variation_Data_Store_CPT',
		'shipping-zone'         => 'WC_Shipping_Zone_Data_Store',
		'webhook'               => 'WC_Webhook_Data_Store',
	);

	/**
	 * Contains the name of the current data store's class name.
	 *
	 * @var string
	 */
	private $current_class_name = '';

	/**
	 * The object type this store works with.
	 *
	 * @var string
	 */
	private $object_type = '';


	/**
	 * Tells WC_Data_Store which object (coupon, product, order, etc)
	 * store we want to work with.
	 *
	 * @throws Exception When validation fails.
	 * @param string $object_type Name of object.
	 */
	public function __construct( $object_type ) {
		$this->object_type = $object_type;
		$this->stores      = apply_filters( 'woocommerce_data_stores', $this->stores );

		// If this object type can't be found, check to see if we can load one
		// level up (so if product-type isn't found, we try product).
		if ( ! array_key_exists( $object_type, $this->stores ) ) {
			$pieces      = explode( '-', $object_type );
			$object_type = $pieces[0];
		}

		if ( array_key_exists( $object_type, $this->stores ) ) {
			$store = apply_filters( 'woocommerce_' . $object_type . '_data_store', $this->stores[ $object_type ] );
			if ( is_object( $store ) ) {
				if ( ! $store instanceof WC_Object_Data_Store_Interface ) {
					throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
				}
				$this->current_class_name = get_class( $store );
				$this->instance           = $store;
			} else {
				if ( ! class_exists( $store ) ) {
					throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
				}
				$this->current_class_name = $store;
				$this->instance           = new $store();
			}
		} else {
			throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
		}
	}

	/**
	 * Only store the object type to avoid serializing the data store instance.
	 *
	 * @return array
	 */
	public function __sleep() {
		return array( 'object_type' );
	}

	/**
	 * Re-run the constructor with the object type.
	 *
	 * @throws Exception When validation fails.
	 */
	public function __wakeup() {
		$this->__construct( $this->object_type );
	}

	/**
	 * Loads a data store.
	 *
	 * @param string $object_type Name of object.
	 *
	 * @since 3.0.0
	 * @throws Exception When validation fails.
	 * @return WC_Data_Store
	 */
	public static function load( $object_type ) {
		return new WC_Data_Store( $object_type );
	}

	/**
	 * Returns the class name of the current data store.
	 *
	 * @since 3.0.0
	 * @return string
	 */
	public function get_current_class_name() {
		return $this->current_class_name;
	}

	/**
	 * Reads an object from the data store.
	 *
	 * @since 3.0.0
	 * @param WC_Data $data WooCommerce data instance.
	 */
	public function read( &$data ) {
		$this->instance->read( $data );
	}

	/**
	 * Reads multiple objects from the data store.
	 *
	 * @since 6.9.0
	 * @param array[WC_Data] $objects Array of object instances to read.
	 */
	public function read_multiple( &$objects = array() ) {
		// If the datastore allows for bulk-reading, use it.
		if ( is_callable( array( $this->instance, 'read_multiple' ) ) ) {
			$this->instance->read_multiple( $objects );
		} else {
			foreach ( $objects as &$obj ) {
				$this->read( $obj );
			}
		}
	}

	/**
	 * Create an object in the data store.
	 *
	 * @since 3.0.0
	 * @param WC_Data $data WooCommerce data instance.
	 */
	public function create( &$data ) {
		$this->instance->create( $data );
	}

	/**
	 * Update an object in the data store.
	 *
	 * @since 3.0.0
	 * @param WC_Data $data WooCommerce data instance.
	 */
	public function update( &$data ) {
		$this->instance->update( $data );
	}

	/**
	 * Delete an object from the data store.
	 *
	 * @since 3.0.0
	 * @param WC_Data $data WooCommerce data instance.
	 * @param array   $args Array of args to pass to the delete method.
	 */
	public function delete( &$data, $args = array() ) {
		$this->instance->delete( $data, $args );
	}

	/**
	 * Data stores can define additional functions (for example, coupons have
	 * some helper methods for increasing or decreasing usage). This passes
	 * through to the instance if that function exists.
	 *
	 * @since 3.0.0
	 * @param string $method     Method.
	 * @param mixed  $parameters Parameters.
	 * @return mixed
	 */
	public function __call( $method, $parameters ) {
		if ( is_callable( array( $this->instance, $method ) ) ) {
			$object     = array_shift( $parameters );
			$parameters = array_merge( array( &$object ), $parameters );
			return $this->instance->$method( ...$parameters );
		}
	}

	/**
	 * Check if the data store we are working with has a callable method.
	 *
	 * @param string $method Method name.
	 *
	 * @return bool Whether the passed method is callable.
	 */
	public function has_callable( string $method ) : bool {
		return is_callable( array( $this->instance, $method ) );
	}
}

Directory Contents

Dirs: 28 × Files: 116

Name Size Perms Modified Actions
abstracts DIR
- drwxr-xr-x 2026-06-08 11:45:21
Edit Download
admin DIR
- drwxr-xr-x 2026-06-15 03:42:05
Edit Download
blocks DIR
- drwxr-xr-x 2026-06-08 11:45:23
Edit Download
cli DIR
- drwxr-xr-x 2026-06-08 11:45:25
Edit Download
- drwxr-xr-x 2026-06-08 11:45:25
Edit Download
- drwxr-xr-x 2026-06-08 11:45:26
Edit Download
emails DIR
- drwxr-xr-x 2026-06-08 11:45:26
Edit Download
export DIR
- drwxr-xr-x 2026-06-08 11:45:26
Edit Download
gateways DIR
- drwxr-xr-x 2026-06-08 11:45:26
Edit Download
import DIR
- drwxr-xr-x 2026-06-08 11:45:26
Edit Download
- drwxr-xr-x 2026-06-08 11:44:44
Edit Download
- drwxr-xr-x 2026-06-08 11:45:26
Edit Download
legacy DIR
- drwxr-xr-x 2026-06-08 11:45:27
Edit Download
libraries DIR
- drwxr-xr-x 2026-06-08 11:45:27
Edit Download
- drwxr-xr-x 2026-06-08 11:45:27
Edit Download
- drwxr-xr-x 2026-06-08 11:45:27
Edit Download
- drwxr-xr-x 2026-06-08 11:45:27
Edit Download
queue DIR
- drwxr-xr-x 2026-06-08 11:45:27
Edit Download
- drwxr-xr-x 2026-06-15 03:44:35
Edit Download
rest-api DIR
- drwxr-xr-x 2026-06-08 11:45:28
Edit Download
shipping DIR
- drwxr-xr-x 2026-06-08 11:44:44
Edit Download
- drwxr-xr-x 2026-06-08 11:45:28
Edit Download
- drwxr-xr-x 2026-06-08 11:45:28
Edit Download
tracks DIR
- drwxr-xr-x 2026-06-08 11:45:28
Edit Download
traits DIR
- drwxr-xr-x 2026-06-08 11:45:29
Edit Download
walkers DIR
- drwxr-xr-x 2026-06-08 11:45:29
Edit Download
- drwxr-xr-x 2026-06-08 11:45:29
Edit Download
widgets DIR
- drwxr-xr-x 2026-06-15 03:46:13
Edit Download
131.47 KB lrw-r--r-- 2026-06-08 11:45:23
Edit Download
12.69 KB lrw-r--r-- 2026-06-08 11:45:23
Edit Download
5.27 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
4.68 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
3.45 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
1.78 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
6.89 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
34.80 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
10.41 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
12.79 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
3.37 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
25.37 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
28.48 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
75.57 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
50.35 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
3.34 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
23.08 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
51.69 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
44.64 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
3.37 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
10.34 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
33.28 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
1.29 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
6.59 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
2.26 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
6.59 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
7.34 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
36.64 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
28.37 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
39.64 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
4.24 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
48.17 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
34.44 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
30.43 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
1.99 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
11.46 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
4.33 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
116.71 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
1.28 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
3.90 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
9.41 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
2.21 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
8.98 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
4.08 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
9.99 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
5.80 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
17.61 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
9.58 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
6.49 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
21.39 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
2.55 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
5.99 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
78.38 KB lrw-r--r-- 2026-06-08 11:45:24
Edit Download
14.37 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
6.24 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
39.09 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
33.16 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
1.79 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
13.61 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
14.69 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
17.22 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
7.87 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
13.18 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
4.98 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
4.59 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
6.81 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
2.27 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
2.70 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
23.76 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
20.18 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
37.01 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
4.00 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
7.74 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
15.44 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
5.05 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
21.55 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
276 B lrw-r--r-- 2026-06-08 11:45:25
Edit Download
24.57 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
9.34 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
13.08 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
5.00 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
13.03 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
18.82 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
24.78 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
39.87 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
20.42 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
51.50 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
5.79 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
30.17 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
63.37 KB lrw-r--r-- 2026-06-08 11:45:25
Edit Download
7.07 KB lrw-r--r-- 2026-07-26 21:31:28
Edit Download
14.15 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
21.91 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
4.17 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
20.81 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
15.53 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
79.00 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
5.56 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
39.78 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
49.90 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
2.43 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
8.49 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
43.99 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
5.03 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
5.97 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
9.99 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
69.18 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
13.93 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
17.43 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
142.51 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
12.84 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
24.63 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
107.05 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
36.73 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
5.91 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download
2.01 KB lrw-r--r-- 2026-06-08 11:45:29
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).