| 1 |
<?php |
| 2 |
/** |
| 3 |
* Global registry for WCPOS. |
| 4 |
* |
| 5 |
* - stores instances of classes that may be required to remove_action or remove_filter. |
| 6 |
* |
| 7 |
* @author Paul Kilmurray <paul@kilbot.com> |
| 8 |
* |
| 9 |
* @see https://wcpos.com |
| 10 |
* @package WCPOS\WooCommercePOS |
| 11 |
*/ |
| 12 |
|
| 13 |
namespace WCPOS\WooCommercePOS; |
| 14 |
|
| 15 |
/** |
| 16 |
* Registry class. |
| 17 |
*/ |
| 18 |
class Registry { |
| 19 |
/** |
| 20 |
* Singleton instance. |
| 21 |
* |
| 22 |
* @var Registry |
| 23 |
*/ |
| 24 |
private static $instance = null; |
| 25 |
|
| 26 |
/** |
| 27 |
* Storage for the registry. |
| 28 |
* |
| 29 |
* @var array |
| 30 |
*/ |
| 31 |
private $storage = array(); |
| 32 |
|
| 33 |
/** |
| 34 |
* Gets the singleton instance of the registry. |
| 35 |
*/ |
| 36 |
public static function get_instance() { |
| 37 |
if ( null === self::$instance ) { |
| 38 |
self::$instance = new self(); |
| 39 |
} |
| 40 |
|
| 41 |
return self::$instance; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Registers a new instance. |
| 46 |
* |
| 47 |
* @param string $key The registry key. |
| 48 |
* @param object $object The object to store. |
| 49 |
*/ |
| 50 |
public function set( $key, $object ): void { |
| 51 |
$this->storage[ $key ] = $object; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Retrieves an instance by key. |
| 56 |
* |
| 57 |
* @param string $key The registry key. |
| 58 |
*/ |
| 59 |
public function get( $key ) { |
| 60 |
return $this->storage[ $key ] ?? null; |
| 61 |
} |
| 62 |
} |
| 63 |
|