<?php
namespace Svea_Webpay_For_Woocommerce\Traits;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * Trait for gateways that needs to instantiate them self in a singleton way
 */
trait Singleton {

	/**
	 * Static instance of this class
	 *
	 * @var static
	 */
	protected static $instance = null;

	/**
	 * Initialize the gateway
	 *
	 * @return static
	 */
	public static function init() {
		// Check if the instance is already set or if it's not an instance of this class (it's an instance of a child class)
		if ( is_null( static::$instance ) || ! static::$instance instanceof static ) {
			static::$instance = new static();
		}

		return static::$instance;
	}
}
