| 1 |
<?php |
| 2 |
|
| 3 |
namespace BubbleMenu\Publish; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
class Singleton { |
| 8 |
private static $instance; |
| 9 |
private array $value = []; |
| 10 |
|
| 11 |
private function __construct() {} |
| 12 |
|
| 13 |
public static function getInstance() { |
| 14 |
if (null === static::$instance) { |
| 15 |
static::$instance = new static(); |
| 16 |
} |
| 17 |
|
| 18 |
return static::$instance; |
| 19 |
} |
| 20 |
|
| 21 |
public function setValue($key, $value) { |
| 22 |
$this->value[$key] = $value; |
| 23 |
} |
| 24 |
|
| 25 |
public function getValue(): array { |
| 26 |
return $this->value; |
| 27 |
} |
| 28 |
|
| 29 |
public function hasKey( $key ) : bool { |
| 30 |
return array_key_exists( $key, $this->value ); |
| 31 |
} |
| 32 |
|
| 33 |
public function getValueByKey($key) { |
| 34 |
if($this->hasKey($key)) { |
| 35 |
return $this->value[$key]; |
| 36 |
} |
| 37 |
|
| 38 |
// Return null or throw an exception if the key does not exist |
| 39 |
return null; |
| 40 |
} |
| 41 |
} |