<?php
/**
 * Singleton trait.
 *
 * @package MadeByAura\Prime\Helpers
 * @author  MadeByAura.com
 */

namespace MadeByAura\Prime\Helpers;

defined( 'ABSPATH' ) || die();

/**
 * Singleton trait.
 */
trait SingletonTrait {
	/**
	 * The single instance of the class.
	 *
	 * @var object
	 */
	protected static $instance = null;

	/**
	 * Constructor.
	 */
	private function __construct() {}

	/**
	 * Disable cloning.
	 */
	final public function __clone() {
		_doing_it_wrong(
			__FUNCTION__,
			esc_html__( 'Cloning instances of this class is forbidden', 'aura-prime' ),
			'1.0.0',
		);
	}

	/**
	 * Disable unserializing.
	 */
	final public function __wakeup() {
		_doing_it_wrong(
			__FUNCTION__,
			esc_html__( 'Unserializing instances of this class is forbidden', 'aura-prime' ),
			'1.0.0',
		);
	}

	/**
	 * Get class instance.
	 *
	 * @return object  Instance.
	 */
	final public static function init() {
		if ( null === static::$instance ) {
			static::$instance = new static();
		}

		return static::$instance;
	}
}
