<?php

declare(strict_types=1);

namespace Signocore\Multilanguage\Infrastructure\Traits;

if (!defined('ABSPATH')) {
	exit;
}

/**
 * Singleton trait for classes that should only have one instance.
 *
 * @phpstan-consistent-constructor
 */
trait Singleton
{
	/** @var static|null */
	protected static ?self $instance = null;

	final public static function load(): static
	{
		if (is_null(static::$instance)) {
			/** @phpstan-ignore-next-line new.static */
			static::$instance = new static();
		}

		return static::$instance;
	}

	private function __construct()
	{
		$this->init();
	}

	protected function init(): void {}

	private function __clone() {}

	final public function __wakeup(): void {}
}
