| 1 |
<?php |
| 2 |
|
| 3 |
namespace Better_Payment\Lite\Traits; |
| 4 |
|
| 5 |
trait HasSingletone { |
| 6 |
/** |
| 7 |
* Holds the plugin instance. |
| 8 |
* |
| 9 |
* @since 2.0.0 |
| 10 |
* @access private |
| 11 |
* @static |
| 12 |
* |
| 13 |
* @var static |
| 14 |
*/ |
| 15 |
protected static $instances = array(); |
| 16 |
/** |
| 17 |
* Sets up a single instance of the plugin. |
| 18 |
* |
| 19 |
* @since 2.0.0 |
| 20 |
* @access public |
| 21 |
* @var mixed $args |
| 22 |
* |
| 23 |
* @static |
| 24 |
* |
| 25 |
* @return static An instance of the class. |
| 26 |
*/ |
| 27 |
public static function get_instance( ...$args ) { |
| 28 |
if ( ! isset( self::$instances[ static::class ] ) ) { |
| 29 |
self::$instances[ static::class ] = ! empty( $args ) ? new static( ...$args ) : new static(); |
| 30 |
} |
| 31 |
|
| 32 |
return self::$instances[ static::class ]; |
| 33 |
} |
| 34 |
|
| 35 |
protected function __construct( ...$args ) {} |
| 36 |
} |