1 | <?php |
||
41 | class Registry extends Locker { |
||
42 | |||
43 | /** @var array */ |
||
44 | protected $registrations; |
||
45 | |||
46 | /** @var boolean */ |
||
47 | protected $readOnly; |
||
48 | |||
49 | /** |
||
50 | * Class constructor. |
||
51 | * @param array $registrations the registrations to add |
||
52 | * @param boolean $readOnly initialize mode for the registry |
||
53 | */ |
||
54 | 1 | public function __construct(array $registrations = [], $readOnly = false) { |
|
59 | |||
60 | /** |
||
61 | * Return all assigned registrations as an array. |
||
62 | * @return array |
||
63 | */ |
||
64 | 1 | public function toArray() { |
|
67 | |||
68 | /** |
||
69 | * Add a registration to the registry. |
||
70 | * @param mixed $registrations the registrations to add |
||
71 | * @throws \InvalidArgumentException if passed registrations is empty |
||
72 | * @return \Brickoo\Component\Common\Registry |
||
73 | */ |
||
74 | 3 | public function add($registrations) { |
|
84 | |||
85 | /** |
||
86 | * Return the registered value from the given identifier. |
||
87 | * @param string $identifier the identifier so retrieve the value from |
||
88 | * @throws \InvalidArgumentException if the identifier is not valid |
||
89 | * @throws \Brickoo\Component\Common\Exception\IdentifierNotRegisteredException |
||
90 | * @return mixed |
||
91 | */ |
||
92 | 2 | public function get($identifier) { |
|
101 | |||
102 | /** |
||
103 | * Register an identifier-value pair. |
||
104 | * Take care of registering objects who are assigned somewhere else |
||
105 | * as an reference the changes applies to the registered objects as well. |
||
106 | * @param string $identifier the identifier to register |
||
107 | * @param mixed $value the identifier value to register with |
||
108 | * @throws \Brickoo\Component\Common\Exception\DuplicateRegistrationException |
||
109 | * @throws \Brickoo\Component\Common\Exception\ReadonlyModeException |
||
110 | * @return \Brickoo\Component\Common\Registry |
||
111 | */ |
||
112 | 3 | public function register($identifier, $value) { |
|
122 | |||
123 | /** |
||
124 | * Overrides an existing identifier with the new value (!). |
||
125 | * If the identifier ist not registered it will be registered. |
||
126 | * @param string $identifier the identifier to register |
||
127 | * @param mixed $value the identifier value to register |
||
128 | * @throws \Brickoo\Component\Common\Exception\ReadonlyModeException |
||
129 | * @throws \Brickoo\Component\Common\Exception\IdentifierLockedException |
||
130 | * @return \Brickoo\Component\Common\Registry |
||
131 | */ |
||
132 | 3 | public function override($identifier, $value) { |
|
142 | |||
143 | /** |
||
144 | * Unregister the identifier and his value. |
||
145 | * @param string $identifier the identifier to unregister |
||
146 | * @throws \Brickoo\Component\Common\Exception\ReadonlyModeException |
||
147 | * @throws \Brickoo\Component\Common\Exception\IdentifierLockedException |
||
148 | * @throws \Brickoo\Component\Common\Exception\IdentifierNotRegisteredException |
||
149 | * @return \Brickoo\Component\Common\Registry |
||
150 | */ |
||
151 | 4 | public function unregister($identifier) { |
|
169 | |||
170 | /** |
||
171 | * Check if the identifier is registered. |
||
172 | * @param string $identifier the identifier to check |
||
173 | * @return boolean |
||
174 | */ |
||
175 | 1 | public function isRegistered($identifier) { |
|
179 | |||
180 | /** |
||
181 | * Sets the read only mode for all registrations. |
||
182 | * True to allow read only, write operations will be not allowed. |
||
183 | * False for enable read and write operations, locked identifiers will still being locked . |
||
184 | * @param boolean $mode the mode to set |
||
185 | * @return \Brickoo\Component\Common\Registry |
||
186 | */ |
||
187 | 1 | public function setReadOnly($mode = true) { |
|
193 | |||
194 | /** |
||
195 | * Check if the mode is currently set to read only. |
||
196 | * @return boolean |
||
197 | */ |
||
198 | 2 | public function isReadOnly() { |
|
201 | |||
202 | /** |
||
203 | * Countable interface implementation. |
||
204 | * Returns the number of registrations. |
||
205 | * @see Countable::count() |
||
206 | * @return integer |
||
207 | */ |
||
208 | 1 | public function count() { |
|
211 | |||
212 | /** |
||
213 | * Returns the number of locked identifiers. |
||
214 | * @return integer |
||
215 | */ |
||
216 | 1 | public function countLocked() { |
|
219 | |||
220 | /** {@inheritDoc} */ |
||
221 | 1 | public function isIdentifierAvailable($identifier) { |
|
224 | |||
225 | /** |
||
226 | * Set the registered identifier and value. |
||
227 | * @param string $identifier |
||
228 | * @param mixed $value |
||
229 | * @throws Exception\DuplicateRegistrationException |
||
230 | * @throws Exception\ReadonlyModeException |
||
231 | * @return \Brickoo\Component\Common\Registry |
||
232 | */ |
||
233 | 3 | private function set($identifier, $value) { |
|
241 | |||
242 | } |
||
243 |