HEX
Server: LiteSpeed
System: Linux eko108.isimtescil.net 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: uyarreklamcomtr (11202)
PHP: 7.4.33
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/ProductIDMap.php.tar
uyarreklam.com.tr/httpdocs/wp-content/plugins/google-listings-and-ads/src/Value/ProductIDMap.php000064400000003745151550323270031711 0ustar00var/www/vhosts<?php
declare( strict_types=1 );

// phpcs:disable WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase

namespace Automattic\WooCommerce\GoogleListingsAndAds\Value;

use Automattic\WooCommerce\GoogleListingsAndAds\Exception\InvalidValue;
use ArrayObject;

defined( 'ABSPATH' ) || exit;

/**
 * Class ProductIDMap
 *
 * Represents an array of WooCommerce product IDs mapped to Google product IDs as their key.
 *
 * @package Automattic\WooCommerce\GoogleListingsAndAds\Value
 */
class ProductIDMap extends ArrayObject implements ValueInterface {

	/**
	 * ProductIDMap constructor.
	 *
	 * @param int[]  $product_ids   An array of WooCommerce product IDs mapped to Google product IDs as their key.
	 * @param int    $flags         Flags to control the behaviour of the ArrayObject object.
	 * @param string $iteratorClass Specify the class that will be used for iteration of the ArrayObject object. ArrayIterator is the default class used.
	 *
	 * @throws InvalidValue When an invalid WooCommerce product ID or Google product ID is provided in the map.
	 */
	public function __construct( $product_ids = [], $flags = 0, $iteratorClass = 'ArrayIterator' ) {
		$this->validate( $product_ids );

		parent::__construct( $product_ids, $flags, $iteratorClass );
	}

	/**
	 * Get the value of the object.
	 *
	 * @return array
	 */
	public function get(): array {
		return $this->getArrayCopy();
	}

	/**
	 * @param int[] $product_ids An array of WooCommerce product IDs mapped to Google product IDs as their key.
	 *
	 * @throws InvalidValue When an invalid WooCommerce product ID or Google product ID is provided in the map.
	 */
	protected function validate( array $product_ids ) {
		foreach ( $product_ids as $google_id => $wc_product_id ) {
			$wc_product_id = filter_var( $wc_product_id, FILTER_VALIDATE_INT );
			if ( false === $wc_product_id ) {
				throw InvalidValue::not_integer( 'product_id' );
			}
			if ( ! is_string( $google_id ) ) {
				throw InvalidValue::not_string( 'google_id' );
			}
		}
	}
}