| 1 |
<?php |
| 2 |
/** |
| 3 |
* Trait Singleton |
| 4 |
* |
| 5 |
* @link http://wpmudev.com |
| 6 |
* @since 1.0.0 |
| 7 |
* @author Joel James <[email protected]> |
| 8 |
* @package WPMUDEV\Hub\Connector |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace WPMUDEV\Hub\Connector; |
| 12 |
|
| 13 |
defined( 'WPINC' ) || die(); |
| 14 |
|
| 15 |
trait Singleton { |
| 16 |
|
| 17 |
/** |
| 18 |
* Instance holder. |
| 19 |
* |
| 20 |
* @var static $instance |
| 21 |
*/ |
| 22 |
private static $instance; |
| 23 |
|
| 24 |
/** |
| 25 |
* Instance obtaining method. |
| 26 |
* |
| 27 |
* @since 1.0.0 |
| 28 |
* |
| 29 |
* @return static Called class instance. |
| 30 |
*/ |
| 31 |
public static function get() { |
| 32 |
$called_class_name = get_called_class(); |
| 33 |
|
| 34 |
// Only if not already exist. |
| 35 |
if ( ! self::$instance instanceof $called_class_name ) { |
| 36 |
self::$instance = new $called_class_name(); |
| 37 |
} |
| 38 |
|
| 39 |
return self::$instance; |
| 40 |
} |
| 41 |
} |
| 42 |
|