1 | <?php |
||
34 | class Session implements LoggerAwareInterface |
||
35 | { |
||
36 | protected $connection; |
||
37 | protected $client_holder; |
||
38 | protected $client_poolers = []; |
||
39 | protected $stamp; |
||
40 | protected $is_shutdown = false; |
||
41 | |||
42 | use LoggerAwareTrait; |
||
43 | |||
44 | /** |
||
45 | * __construct |
||
46 | * |
||
47 | * Constructor. |
||
48 | * In order to create a physical connection to the database, it requires a |
||
49 | * 'dsn' parameter from the ParameterHolder. |
||
50 | * |
||
51 | * @param Connection $connection |
||
52 | * @param ClientHolder $client_holder |
||
53 | * @param string $stamp |
||
54 | */ |
||
55 | public function __construct( |
||
67 | |||
68 | /** |
||
69 | * __destruct |
||
70 | * |
||
71 | * A short description here |
||
72 | * |
||
73 | * @return null |
||
74 | */ |
||
75 | public function __destruct() |
||
81 | |||
82 | /** |
||
83 | * shutdown |
||
84 | * |
||
85 | * Gently shutdown all clients when the Session is getting down prior to |
||
86 | * connection termination. |
||
87 | * |
||
88 | * @return null |
||
89 | */ |
||
90 | public function shutdown() |
||
109 | |||
110 | /** |
||
111 | * getStamp |
||
112 | * |
||
113 | * Return the session's stamp if any |
||
114 | * |
||
115 | * @return string|null |
||
116 | */ |
||
117 | public function getStamp() |
||
121 | |||
122 | /** |
||
123 | * getLogger |
||
124 | * |
||
125 | * Return the logger if any. |
||
126 | * |
||
127 | * @return LoggerInterface|null |
||
128 | */ |
||
129 | public function getLogger() |
||
133 | |||
134 | /** |
||
135 | * hasLogger |
||
136 | * |
||
137 | * Return true if a logger is set. |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | public function hasLogger() |
||
145 | |||
146 | /** |
||
147 | * getConnection |
||
148 | * |
||
149 | * Return the database connection. |
||
150 | * |
||
151 | * @return Connection |
||
152 | */ |
||
153 | public function getConnection() |
||
157 | |||
158 | /** |
||
159 | * registerClient |
||
160 | * |
||
161 | * Initialize a connection client with context and register it in the |
||
162 | * client holder. |
||
163 | * |
||
164 | * @param ClientInterface $client |
||
165 | * @return Session $this |
||
166 | */ |
||
167 | public function registerClient(ClientInterface $client) |
||
181 | |||
182 | /** |
||
183 | * getClient |
||
184 | * |
||
185 | * Return a Client from its type and identifier. |
||
186 | * |
||
187 | * @param string $type |
||
188 | * @param string $identifier |
||
189 | * @return Client or null if not found. |
||
190 | */ |
||
191 | public function getClient($type, $identifier) |
||
195 | |||
196 | /** |
||
197 | * hasClient |
||
198 | * |
||
199 | * Tell if a client exist or not. |
||
200 | * |
||
201 | * @param string $type |
||
202 | * @param string $name |
||
203 | * @return bool |
||
204 | */ |
||
205 | public function hasClient($type, $name) |
||
209 | |||
210 | /** |
||
211 | * registerClientPooler |
||
212 | * |
||
213 | * Add or replace a Client pooler for the specified type. |
||
214 | * |
||
215 | * @param ClientPoolerInterface $client_pooler |
||
216 | * @return Session $this |
||
217 | */ |
||
218 | public function registerClientPooler(ClientPoolerInterface $client_pooler) |
||
235 | |||
236 | /** |
||
237 | * hasPoolerForType |
||
238 | * |
||
239 | * Tell if a pooler exist or not. |
||
240 | * |
||
241 | * @param string $type |
||
242 | * @return bool |
||
243 | */ |
||
244 | public function hasPoolerForType($type) |
||
248 | |||
249 | /** |
||
250 | * getPoolerForType |
||
251 | * |
||
252 | * Get the registered for the given type. |
||
253 | * |
||
254 | * @param string $type |
||
255 | * @throws FoundationException if pooler does not exist |
||
256 | * @return ClientPoolerInterface |
||
257 | */ |
||
258 | public function getPoolerForType($type) |
||
283 | |||
284 | /** |
||
285 | * getAllClientForType |
||
286 | * |
||
287 | * Return all instances of clients for a given type. |
||
288 | * |
||
289 | * @param string $type |
||
290 | * @return ClientInterface |
||
291 | */ |
||
292 | public function getAllClientForType($type) |
||
296 | |||
297 | /** |
||
298 | * getClientUsingPooler |
||
299 | * |
||
300 | * Summon a pooler to retrieve a client. If the pooler does not exist, a |
||
301 | * FoundationException is thrown. |
||
302 | * |
||
303 | * @param string $type |
||
304 | * @param string $identifier |
||
305 | * @return ClientInterface |
||
306 | */ |
||
307 | public function getClientUsingPooler($type, $identifier) |
||
311 | |||
312 | /** |
||
313 | * __call |
||
314 | * |
||
315 | * Create handy methods to access clients through a pooler. |
||
316 | * |
||
317 | * @param string $method |
||
318 | * @param array $arguments |
||
319 | * @throws \BadFunctionCallException if unknown method |
||
320 | * @throws FoundationException if no poolers found |
||
321 | * @return ClientInterface |
||
322 | */ |
||
323 | public function __call($method, $arguments) |
||
334 | |||
335 | /** |
||
336 | * getRegisterPoolersNames |
||
337 | * |
||
338 | * Useful to test & debug. |
||
339 | * |
||
340 | * @return array |
||
341 | */ |
||
342 | public function getRegisterPoolersNames() |
||
346 | } |
||
347 |