Hoa central
Registry.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Registry;
38 
39 use Hoa\Core;
40 
49 class Registry extends \ArrayObject
50 {
56  private static $_instance = null;
57 
58 
59 
66  public function __construct()
67  {
68  throw new Exception(
69  'Cannot instance the %s object. Use set, get, remove ' .
70  'and isRegistered static methods instead.',
71  0,
72  __CLASS__
73  );
74 
75  return;
76  }
77 
83  protected static function getInstance()
84  {
85  if (null === static::$_instance) {
86  static::$_instance = new parent();
87  }
88 
89  return static::$_instance;
90  }
91 
99  public static function set($index, $value)
100  {
101  static::getInstance()->offsetSet($index, $value);
102 
103  return;
104  }
105 
113  public static function get($index)
114  {
115  $registry = static::getInstance();
116 
117  if (false === $registry->offsetExists($index)) {
118  throw new Exception(
119  'Registry %s does not exist.',
120  1,
121  $index
122  );
123  }
124 
125  return $registry->offsetGet($index);
126  }
127 
134  public static function isRegistered($index)
135  {
136  return static::getInstance()->offsetExists($index);
137  }
138 
145  public static function remove($index)
146  {
147  static::getInstance()->offsetUnset($index);
148 
149  return;
150  }
151 }
152 
161 class _Protocol extends Core\Protocol
162 {
168  protected $_name = 'Registry';
169 
170 
171 
178  public function reachId($id)
179  {
180  return Registry::get($id);
181  }
182 }
183 
187 Core\Consistency::flexEntity('Hoa\Registry\Registry');
188 
193 $protocol = Core::getInstance()->getProtocol();
194 $protocol['Library'][] = new _Protocol();
static isRegistered($index)
Definition: Registry.php:134
static set($index, $value)
Definition: Registry.php:99
static get($index)
Definition: Registry.php:113
static getInstance()
Definition: Core.php:193
static getInstance()
Definition: Registry.php:83