<?php

/**
 * Singleton class trait.
 *
 * @package northmill-online-shared
 */
namespace Northmill_Online_Shared_Checkout\Northmill_Online_Shared\Traits;

/**
 * Trait SingletonTrait
 *
 * Provides a singleton instance for a class.
 *
 * @used Northmill Sync
 */
trait Singleton_Trait
{
    /**
     * Represents an instance of the class.
     *
     * @var null|static
     */
    private static ?self $instance = null;
    /**
     * Get the instance of this class
     *
     * If the instance doesn't already exist, instantiate a new instance of the class
     *
     * @return static
     */
    public static function instance(): self
    {
        if (null === self::$instance) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    /**
     * Prevent cloning.
     */
    private function __clone()
    {
    }
}
