2023-08-09 11:48:49 +01:00
|
|
|
<?php
|
2023-08-15 08:27:59 +01:00
|
|
|
/**
|
|
|
|
* The Singleton Trait can be used to add singleton behaviour to a class.
|
|
|
|
*
|
|
|
|
* @package WooCommerce\PayPalCommerce\Common\Pattern
|
|
|
|
*/
|
2023-08-09 11:48:49 +01:00
|
|
|
|
2023-08-15 08:27:59 +01:00
|
|
|
namespace WooCommerce\PayPalCommerce\Common\Pattern;
|
2023-08-09 11:48:49 +01:00
|
|
|
|
2023-08-15 08:27:59 +01:00
|
|
|
/**
|
|
|
|
* Class SingletonTrait.
|
|
|
|
*/
|
2023-08-09 11:48:49 +01:00
|
|
|
trait SingletonTrait {
|
|
|
|
/**
|
|
|
|
* The single instance of the class.
|
|
|
|
*
|
|
|
|
* @var self
|
|
|
|
*/
|
|
|
|
protected static $instance = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Static method to get the instance of the Singleton class
|
|
|
|
*
|
|
|
|
* @return self|null
|
|
|
|
*/
|
|
|
|
public static function get_instance(): ?self {
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Static method to get the instance of the Singleton class
|
|
|
|
*
|
|
|
|
* @param self $instance
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
protected static function set_instance( self $instance ): self {
|
|
|
|
self::$instance = $instance;
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|