1 | <?php |
||
28 | class Pomm implements \ArrayAccess, LoggerAwareInterface |
||
29 | { |
||
30 | protected $builders = []; |
||
31 | protected $post_configurations = []; |
||
32 | protected $sessions = []; |
||
33 | protected $default; |
||
34 | |||
35 | use LoggerAwareTrait; |
||
36 | |||
37 | /** |
||
38 | * __construct |
||
39 | * |
||
40 | * Instantiate a new Pomm Service class. It takes an array of |
||
41 | * configurations as parameter. Following configuration settings are |
||
42 | * supported by this service for each configuration: |
||
43 | * |
||
44 | * class_name name of the DatabaseConfiguration class to instantiate. |
||
45 | * |
||
46 | * @param array $configurations |
||
47 | */ |
||
48 | public function __construct(array $configurations = []) |
||
63 | |||
64 | /** |
||
65 | * checkSessionBuilderClass |
||
66 | * |
||
67 | * Check if the given builder class is valid. |
||
68 | * |
||
69 | * @param string $builder_class |
||
70 | * @throws FoundationException if not valid |
||
71 | * @return string $builder_class |
||
72 | */ |
||
73 | private function checkSessionBuilderClass($builder_class) |
||
99 | |||
100 | /** |
||
101 | * setDefaultBuilder |
||
102 | * |
||
103 | * Set the name for the default session builder. |
||
104 | * |
||
105 | * @param string $name |
||
106 | * @return Pomm $this |
||
107 | * @throws FoundationException |
||
108 | */ |
||
109 | public function setDefaultBuilder($name) |
||
124 | |||
125 | /** |
||
126 | * getDefaultSession |
||
127 | * |
||
128 | * Return a session built by the default session builder. |
||
129 | * |
||
130 | * @return BaseSession |
||
131 | * @throws FoundationException |
||
132 | */ |
||
133 | public function getDefaultSession() |
||
144 | |||
145 | /** |
||
146 | * isDefaultSession |
||
147 | * |
||
148 | * Check if $name is a default session builder |
||
149 | * |
||
150 | * @param string $name |
||
151 | * @return bool |
||
152 | */ |
||
153 | public function isDefaultSession($name) |
||
157 | |||
158 | /** |
||
159 | * addBuilder |
||
160 | * |
||
161 | * Add a new session builder. Override any previously existing builder with |
||
162 | * the same name. |
||
163 | * |
||
164 | * @param string $builder_name |
||
165 | * @param VanillaSessionBuilder $builder |
||
166 | * @return Pomm $this |
||
167 | */ |
||
168 | public function addBuilder($builder_name, VanillaSessionBuilder $builder) |
||
179 | |||
180 | /** |
||
181 | * addPostConfiguration |
||
182 | * |
||
183 | * Add a environment dependent post configuration callable that will be run |
||
184 | * once after the session creation. |
||
185 | * |
||
186 | * @param string $name |
||
187 | * @param callable $callable |
||
188 | * @return Pomm $this |
||
189 | */ |
||
190 | public function addPostConfiguration($name, callable $callable) |
||
199 | |||
200 | /** |
||
201 | * hasBuilder |
||
202 | * |
||
203 | * Return if true or false the given builder exists. |
||
204 | * |
||
205 | * @param string $name |
||
206 | * @return bool |
||
207 | */ |
||
208 | public function hasBuilder($name) |
||
212 | |||
213 | /** |
||
214 | * removeBuilder |
||
215 | * |
||
216 | * Remove the builder with the given name. |
||
217 | * |
||
218 | * @param string $name |
||
219 | * @throws FoundationException if name does not exist. |
||
220 | * @return Pomm $this |
||
221 | */ |
||
222 | public function removeBuilder($name) |
||
231 | |||
232 | /** |
||
233 | * getBuilder |
||
234 | * |
||
235 | * Return the given builder. |
||
236 | * |
||
237 | * @param string $name |
||
238 | * @return VanillaSessionBuilder |
||
239 | */ |
||
240 | public function getBuilder($name) |
||
244 | |||
245 | /** |
||
246 | * getSession |
||
247 | * |
||
248 | * Return a session from the pool. If no session exists, an attempt is made |
||
249 | * to create one. |
||
250 | * |
||
251 | * @param string $name |
||
252 | * @return BaseSession |
||
253 | */ |
||
254 | public function getSession($name) |
||
262 | |||
263 | /** |
||
264 | * createSession |
||
265 | * |
||
266 | * Create a new session using a session_builder and set it to the pool. Any |
||
267 | * previous session for this name is overrided. |
||
268 | * |
||
269 | * @param string $name |
||
270 | * @throws FoundationException if builder does not exist. |
||
271 | * @return BaseSession |
||
272 | */ |
||
273 | public function createSession($name) |
||
293 | |||
294 | /** |
||
295 | * hasSession |
||
296 | * |
||
297 | * Does a given session exist in the pool ? |
||
298 | * |
||
299 | * @param string $name |
||
300 | * @return bool |
||
301 | */ |
||
302 | public function hasSession($name) |
||
306 | |||
307 | /** |
||
308 | * removeSession |
||
309 | * |
||
310 | * Remove a session from the pool if it exists. |
||
311 | * |
||
312 | * @param string $name |
||
313 | * @throws FoundationException if no builders with that name exist |
||
314 | * @return Pomm $this |
||
315 | */ |
||
316 | public function removeSession($name) |
||
324 | |||
325 | /** |
||
326 | * getSessionBuilders |
||
327 | * |
||
328 | * Return the builders. This is mainly done for testing |
||
329 | * purposes. |
||
330 | * |
||
331 | * @return array |
||
332 | */ |
||
333 | public function getSessionBuilders() |
||
337 | |||
338 | /** |
||
339 | * @see ArrayAccess |
||
340 | */ |
||
341 | public function offsetGet($offset) |
||
345 | |||
346 | /** |
||
347 | * @see ArrayAccess |
||
348 | */ |
||
349 | public function offsetSet($offset, $value) |
||
353 | |||
354 | /** |
||
355 | * @see ArrayAccess |
||
356 | */ |
||
357 | public function offsetUnset($offset) |
||
361 | |||
362 | /** |
||
363 | * @see ArrayAccess |
||
364 | */ |
||
365 | public function offsetExists($offset) |
||
369 | |||
370 | /** |
||
371 | * shutdown |
||
372 | * |
||
373 | * Shutdown and remove sessions from the service. If no arguments are |
||
374 | * given, all the instantiated sessions are shutdown. Otherwise, only given |
||
375 | * sessions are shutdown. |
||
376 | * |
||
377 | * @param array $session_names |
||
378 | * @return Pomm $this |
||
379 | */ |
||
380 | public function shutdown(array $session_names = []) |
||
399 | |||
400 | /** |
||
401 | * builderMustExist |
||
402 | * |
||
403 | * Throw a FoundationException if the given builder does not exist. |
||
404 | * |
||
405 | * @param string $name |
||
406 | * @throws FoundationException |
||
407 | * @return Pomm $this |
||
408 | */ |
||
409 | private function builderMustExist($name) |
||
431 | } |
||
432 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.