2019-05-10 22:33:12 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2019-06-19 13:48:23 +00:00
|
|
|
* Singleton class trait.
|
2019-05-10 22:33:12 +00:00
|
|
|
*
|
2020-09-17 14:56:08 +00:00
|
|
|
* @package WooCommerce\Utilities
|
2019-05-10 22:33:12 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-21 09:40:39 +00:00
|
|
|
namespace Automattic\WooCommerce\RestApi\Utilities;
|
2019-05-10 22:33:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Singleton trait.
|
|
|
|
*/
|
2019-05-22 12:24:03 +00:00
|
|
|
trait SingletonTrait {
|
2019-05-10 22:33:12 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2020-09-18 07:55:26 +00:00
|
|
|
final public function __wakeup() {
|
|
|
|
wc_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of this class is forbidden.', 'woocommerce' ), '4.6' );
|
|
|
|
die();
|
|
|
|
}
|
2019-05-10 22:33:12 +00:00
|
|
|
}
|