• File: SingletonTrait.php
  • Full Path: /home/chassiw/www/wp-content/plugins/woocommerce/includes/rest-api/Utilities/SingletonTrait.php
  • File size: 738 bytes
  • MIME-type: text/x-php
  • Charset: utf-8
<?php
/**
 * Singleton class trait.
 *
 * @package Automattic/WooCommerce/Utilities
 */

namespace Automattic\WooCommerce\RestApi\Utilities;

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

	/**
	 * Constructor
	 *
	 * @return void
	 */
	protected function __construct() {}

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

	/**
	 * Prevent cloning.
	 */
	private function __clone() {}

	/**
	 * Prevent unserializing.
	 */
	private function __wakeup() {}
}