HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //proc/thread-self/cwd/wp-content/plugins/tutor/ecommerce/PaymentGateways/GatewayFactory.php
<?php
/**
 * Payment gateway factory class
 *
 * @package Tutor\Ecommerce
 * @author Themeum
 * @link https://themeum.com
 * @since 3.0.0
 */

namespace Tutor\PaymentGateways;

/**
 * Create object of a payment gateway
 */
abstract class GatewayFactory {

	/**
	 * Create an instance of the specified payment gateway.
	 *
	 * @param string $gateway The fully qualified class name of the gateway.
	 * @return GatewayBase
	 * @throws \InvalidArgumentException If the class does not exist or is not an instance of GatewayBase.
	 */
	public static function create( string $gateway ): GatewayBase {
		if ( ! class_exists( $gateway ) ) {
			throw new \InvalidArgumentException( esc_html( "Gateway class {$gateway} does not exist." ) );
		}

		$obj = new $gateway();

		// Ensure the object is an instance of GatewayBase.
		if ( ! $obj instanceof GatewayBase ) {
			throw new \InvalidArgumentException( esc_html( "Gateway {$gateway} must be an instance of GatewayBase." ) );
		}

		return $obj;
	}
}