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/BatchProductIDRequestEntry.php.tar
httpdocs/wp-content/plugins/google-listings-and-ads/src/Google/BatchProductIDRequestEntry.php000064400000003342151546345500034746 0ustar00var/www/vhosts/uyarreklam.com.tr<?php
declare( strict_types=1 );

namespace Automattic\WooCommerce\GoogleListingsAndAds\Google;

use Automattic\WooCommerce\GoogleListingsAndAds\Value\ProductIDMap;

defined( 'ABSPATH' ) || exit;

/**
 * Class BatchProductIDRequestEntry
 *
 * @package Automattic\WooCommerce\GoogleListingsAndAds\Google
 */
class BatchProductIDRequestEntry {
	/**
	 * @var int
	 */
	protected $wc_product_id;

	/**
	 * @var string The Google product REST ID.
	 */
	protected $product_id;

	/**
	 * BatchProductIDRequestEntry constructor.
	 *
	 * @param int    $wc_product_id
	 * @param string $product_id
	 */
	public function __construct( int $wc_product_id, string $product_id ) {
		$this->wc_product_id = $wc_product_id;
		$this->product_id    = $product_id;
	}

	/**
	 * @return int
	 */
	public function get_wc_product_id(): int {
		return $this->wc_product_id;
	}

	/**
	 * @return string
	 */
	public function get_product_id(): string {
		return $this->product_id;
	}

	/**
	 * @param ProductIDMap $product_id_map
	 *
	 * @return BatchProductIDRequestEntry[]
	 */
	public static function create_from_id_map( ProductIDMap $product_id_map ): array {
		$product_entries = [];
		foreach ( $product_id_map as $google_product_id => $wc_product_id ) {
			$product_entries[] = new BatchProductIDRequestEntry( $wc_product_id, $google_product_id );
		}

		return $product_entries;
	}

	/**
	 * @param BatchProductIDRequestEntry[] $request_entries
	 *
	 * @return ProductIDMap $product_id_map
	 */
	public static function convert_to_id_map( array $request_entries ): ProductIDMap {
		$id_map = [];
		foreach ( $request_entries as $request_entry ) {
			$id_map[ $request_entry->get_product_id() ] = $request_entry->get_wc_product_id();
		}

		return new ProductIDMap( $id_map );
	}
}