array_to_csv.php
3 years ago
date_format.php
3 years ago
exact_range.php
3 years ago
number_formatter.php
3 years ago
relative_range.php
3 years ago
request.php
3 years ago
salt.php
3 years ago
security.php
3 years ago
singleton.php
3 years ago
string.php
3 years ago
timezone.php
3 years ago
url.php
3 years ago
wp-async-request.php
3 years ago
singleton.php
62 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | trait Singleton |
| 6 | { |
| 7 | /** |
| 8 | * Singleton Instance |
| 9 | * |
| 10 | * @var Singleton |
| 11 | */ |
| 12 | private static $instance; |
| 13 | |
| 14 | /** |
| 15 | * Private Constructor |
| 16 | * |
| 17 | * We can't use the constructor to create an instance of the class |
| 18 | * |
| 19 | * @return void |
| 20 | */ |
| 21 | private function __construct() |
| 22 | { |
| 23 | // Don't do anything, we don't want to be initialized |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Get the singleton instance |
| 28 | * |
| 29 | * @return Singleton |
| 30 | */ |
| 31 | public static function getInstance() |
| 32 | { |
| 33 | if (!isset(self::$instance)) { |
| 34 | self::$instance = new self(); |
| 35 | } |
| 36 | |
| 37 | return self::$instance; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Private clone method to prevent cloning of the instance of the |
| 42 | * Singleton instance. |
| 43 | * |
| 44 | * @return void |
| 45 | */ |
| 46 | private function __clone() |
| 47 | { |
| 48 | // Don't do anything, we don't want to be cloned |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Private unserialize method to prevent unserializing of the Singleton |
| 53 | * instance. |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | public function __wakeup() |
| 58 | { |
| 59 | // Don't do anything, we don't want to be unserialized |
| 60 | } |
| 61 | } |
| 62 |