| 1 |
<?php |
| 2 |
|
| 3 |
namespace FloatMenuLite\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 |
|
| 14 |
public static function getInstance() { |
| 15 |
if ( null === static::$instance ) { |
| 16 |
static::$instance = new static(); |
| 17 |
} |
| 18 |
|
| 19 |
return static::$instance; |
| 20 |
} |
| 21 |
|
| 22 |
public function setValue( $key, $value ) { |
| 23 |
$this->value[ $key ] = $value; |
| 24 |
} |
| 25 |
|
| 26 |
public function getValue(): array { |
| 27 |
return $this->value; |
| 28 |
} |
| 29 |
|
| 30 |
public function hasKey( $key ): bool { |
| 31 |
return array_key_exists( $key, $this->value ); |
| 32 |
} |
| 33 |
|
| 34 |
public function getValueByKey( $key ) { |
| 35 |
if ( $this->hasKey( $key ) ) { |
| 36 |
return $this->value[ $key ]; |
| 37 |
} |
| 38 |
|
| 39 |
return null; |
| 40 |
} |
| 41 |
} |