HEX
Server: LiteSpeed
System: Linux server484.bertina.biz 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: alvnails (1268)
PHP: 8.2.29
Disabled: mail
Upload Files
File: /home/alvnails/public_html/wp-content/plugins/multisite-language-switcher/includes/MslsRegistry.php
<?php declare( strict_types=1 );

namespace lloc\Msls;

/**
 * Registry instead of singletons
 *
 * @package Msls
 */
class MslsRegistry {

	/**
	 * Generic container
	 *
	 * @var string[]
	 */
	private static $arr = array();

	/**
	 * Instance
	 *
	 * @var ?MslsRegistry
	 */
	private static $instance = null;

	/**
	 * Get an object by key
	 *
	 * @param string $key
	 *
	 * @return mixed
	 */
	private function get( $key ) {
		return self::$arr[ $key ] ?? null;
	}

	/**
	 * Set an object
	 *
	 * @param string $key
	 * @param mixed  $instance
	 */
	private function set( string $key, $instance ): void {
		self::$arr[ $key ] = $instance;
	}

	/**
	 * Registry is a singleton
	 *
	 * @return MslsRegistry
	 */
	public static function instance(): self {
		if ( self::$instance === null ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	/**
	 * Static get_object calls get
	 *
	 * @param string $key
	 *
	 * @return mixed
	 */
	public static function get_object( $key ) {
		return self::instance()->get( $key );
	}

	/**
	 * Static set_object calls set
	 *
	 * @param string $key
	 * @param mixed  $instance
	 */
	public static function set_object( string $key, $instance ): void {
		self::instance()->set( $key, $instance );
	}
}