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

namespace Automattic\WooCommerce\GoogleListingsAndAds\DB;

use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\AttributeMappingRulesTable;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\BudgetRecommendationTable;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\MerchantIssueTable;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\ShippingRateTable;
use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\ShippingTimeTable;
use Automattic\WooCommerce\GoogleListingsAndAds\Exception\ValidateInterface;

defined( 'ABSPATH' ) || exit;

/**
 * Class TableManager
 *
 * @package Automattic\WooCommerce\GoogleListingsAndAds\DB
 *
 * @since 1.3.0
 */
class TableManager {

	use ValidateInterface;

	protected const VALID_TABLES = [
		AttributeMappingRulesTable::class => true,
		BudgetRecommendationTable::class  => true,
		MerchantIssueTable::class         => true,
		ShippingRateTable::class          => true,
		ShippingTimeTable::class          => true,
	];

	/**
	 * @var Table[]
	 */
	protected $tables;

	/**
	 * TableManager constructor.
	 *
	 * @param Table[] $tables
	 */
	public function __construct( array $tables ) {
		$this->setup_tables( $tables );
	}

	/**
	 * @return Table[]
	 *
	 * @see \Automattic\WooCommerce\GoogleListingsAndAds\DB\Installer::install for installing these tables.
	 */
	public function get_tables(): array {
		return $this->tables;
	}

	/**
	 * Returns a list of table names to be installed.
	 *
	 * @return string[] Table names
	 *
	 * @see TableManager::VALID_TABLES for the list of valid table classes.
	 */
	public static function get_all_table_names(): array {
		$tables = [];
		foreach ( array_keys( self::VALID_TABLES ) as $table_class ) {
			$table_name = call_user_func( [ $table_class, 'get_raw_name' ] );

			$tables[ $table_name ] = $table_name;
		}

		return $tables;
	}

	/**
	 * Set up each of the table controllers.
	 *
	 * @param Table[] $tables
	 */
	protected function setup_tables( array $tables ) {
		foreach ( $tables as $table ) {
			$this->validate_instanceof( $table, Table::class );

			// only include tables from the installable tables list.
			if ( isset( self::VALID_TABLES[ get_class( $table ) ] ) ) {
				$this->tables[] = $table;
			}
		}
	}
}