woocommerce/src/Utilities/SingletonTrait.php

52 lines
737 B
PHP
Raw Normal View History

2019-05-10 22:33:12 +00:00
<?php
/**
* Abstract singleton class.
*
2019-05-22 15:56:55 +00:00
* TODO: move to core?
*
* @package WooCommerce/Utilities
2019-05-10 22:33:12 +00:00
*/
namespace WooCommerce\Utilities;
2019-05-10 22:33:12 +00:00
/**
* Singleton trait.
*/
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.
*/
private function __wakeup() {}
}