SILENT KILLERPanel

Current Path: > home > codekrsu > > cuddlebuds.lk > wp-content > plugins > woocommerce > src > Blocks > Utils


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: /home/codekrsu//cuddlebuds.lk/wp-content/plugins/woocommerce/src/Blocks/Utils

NameTypeSizeLast ModifiedActions
BlockHooksTrait.php File 7059 bytes July 30 2024 19:31:16.
BlockTemplateUtils.php File 31727 bytes July 31 2025 15:46:25.
BlocksSharedState.php File 4339 bytes June 23 2025 19:46:28.
BlocksWpQuery.php File 2133 bytes December 27 2023 00:45:02.
CartCheckoutUtils.php File 14989 bytes May 12 2025 21:07:28.
MiniCartUtils.php File 3594 bytes November 14 2024 01:17:00.
ProductAvailabilityUtils.php File 1320 bytes June 23 2025 19:46:28.
ProductDataUtils.php File 455 bytes August 02 2025 11:56:19.
ProductGalleryUtils.php File 5802 bytes July 30 2025 00:41:58.
StyleAttributesUtils.php File 23677 bytes May 12 2025 21:07:28.
Utils.php File 1240 bytes December 27 2023 00:45:02.
error_log File 759 bytes August 02 2025 11:56:21.

Reading File: /home/codekrsu//cuddlebuds.lk/wp-content/plugins/woocommerce/src/Blocks/Utils/BlocksSharedState.php

<?php

declare(strict_types=1);

namespace Automattic\WooCommerce\Blocks\Utils;

use InvalidArgumentException;

/**
 * Manages the registration of interactivity config and state that is commonly shared by WooCommerce blocks.
 * Initialization only happens on the first call to initialize_shared_config.
 * Intended to be used as a singleton.
 */
trait BlocksSharedState {

	/**
	 * The consent statement for using private APIs of this class.
	 *
	 * @var string
	 */
	private static $consent_statement = 'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WooCommerce';

	/**
	 * The namespace for the config.
	 *
	 * @var string
	 */
	private static $settings_namespace = 'woocommerce';

	/**
	 * Whether the core config has been registered.
	 *
	 * @var boolean
	 */
	private static $core_config_registered = false;

	/**
	 * Cart state.
	 *
	 * @var mixed
	 */
	private static $blocks_shared_cart_state;

	/**
	 * Prevent caching on certain pages
	 */
	private static function prevent_cache() {
		\WC_Cache_Helper::set_nocache_constants();
		nocache_headers();
	}


	/**
	 * Check that the consent statement was passed.
	 *
	 * @param string $consent_statement - The consent statement string.
	 * @return true
	 * @throws \InvalidArgumentException - If the statement does not match the class consent statement string.
	 */
	private static function check_consent( $consent_statement ) {
		if ( $consent_statement !== self::$consent_statement ) {
			throw new InvalidArgumentException( 'This method cannot be called without consenting the API may change.' );
		}

		return true;
	}

	/**
	 * Initialize the shared core config.
	 *
	 * @param string $consent_statement - The consent statement string.
	 */
	public function initialize_shared_config( $consent_statement ) {
		self::check_consent( $consent_statement );

		if ( self::$core_config_registered ) {
			return;
		}

		self::$core_config_registered = true;

		wp_interactivity_config( self::$settings_namespace, self::get_currency_data() );
		wp_interactivity_config( self::$settings_namespace, self::get_locale_data() );
		wp_interactivity_config( self::$settings_namespace, self::get_core_data() );
	}

	/**
	 * Initialize interactivity state for cart that is needed by multiple blocks.
	 *
	 * @param string $consent_statement - The consent statement string.
	 * @return void
	 */
	public function register_cart_interactivity( $consent_statement ) {
		self::check_consent( $consent_statement );

		if ( null === self::$blocks_shared_cart_state ) {
			$cart_exists                    = isset( WC()->cart );
			$cart_has_contents              = $cart_exists && ! WC()->cart->is_empty();
			self::$blocks_shared_cart_state = $cart_exists
				? rest_do_request( new \WP_REST_Request( 'GET', '/wc/store/v1/cart' ) )->data
				: array();

			if ( $cart_has_contents ) {
				self::prevent_cache();
			}

			wp_interactivity_state(
				'woocommerce',
				array(
					'cart'     => self::$blocks_shared_cart_state,
					'nonce'    => wp_create_nonce( 'wc_store_api' ),
					'noticeId' => '',
					'restUrl'  => get_rest_url(),
				)
			);
		}
	}

	/**
	 * Get core data to include in settings.
	 *
	 * @return array
	 */
	private static function get_core_data() {
		return [
			'isBlockTheme' => wp_is_block_theme(),
		];
	}

	/**
	 * Get currency data to include in settings.
	 *
	 * @return array
	 */
	private static function get_currency_data() {
		$currency = get_woocommerce_currency();

		return [
			'currency' => [
				'code'              => $currency,
				'precision'         => wc_get_price_decimals(),
				'symbol'            => html_entity_decode( get_woocommerce_currency_symbol( $currency ) ),
				'symbolPosition'    => get_option( 'woocommerce_currency_pos' ),
				'decimalSeparator'  => wc_get_price_decimal_separator(),
				'thousandSeparator' => wc_get_price_thousand_separator(),
				'priceFormat'       => html_entity_decode( get_woocommerce_price_format() ),
			],
		];
	}

	/**
	 * Get locale data to include in settings.
	 *
	 * @return array
	 */
	private static function get_locale_data() {
		global $wp_locale;

		return [
			'locale' => [
				'siteLocale'    => get_locale(),
				'userLocale'    => get_user_locale(),
				'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ),
			],
		];
	}
}

SILENT KILLER Tool