AjaxRequest.php
1 year ago
LogWriter.php
1 year ago
OptionStatus.php
1 year ago
Singleton.php
1 year ago
index.php
1 year ago
Singleton.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | namespace CommerceBird\Admin\Traits; |
| 4 | |
| 5 | use Exception; |
| 6 | |
| 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | exit; |
| 9 | } |
| 10 | |
| 11 | trait Singleton { |
| 12 | /** |
| 13 | * The single instance of the class. |
| 14 | * |
| 15 | * @var object |
| 16 | */ |
| 17 | protected static ?self $instance = null; |
| 18 | |
| 19 | /** |
| 20 | * Constructor |
| 21 | * |
| 22 | * @return void |
| 23 | */ |
| 24 | protected function __construct() { |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Get class instance. |
| 29 | * |
| 30 | * @return object Instance. |
| 31 | */ |
| 32 | final public static function instance(): self { |
| 33 | if ( null === static::$instance ) { |
| 34 | static::$instance = new static(); |
| 35 | } |
| 36 | |
| 37 | return static::$instance; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Prevent unserializing. |
| 42 | * |
| 43 | * @throws Exception |
| 44 | */ |
| 45 | final public function __wakeup() { |
| 46 | throw new Exception( 'Serializing instances of this class is forbidden' ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Prevent cloning. |
| 51 | * |
| 52 | * @throws Exception |
| 53 | */ |
| 54 | private function __clone() { |
| 55 | throw new Exception( 'Serializing instances of this class is forbidden' ); |
| 56 | } |
| 57 | } |
| 58 |