1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb\db\driver;
15
16use Symfony\Component\DependencyInjection\ContainerInterface;
17
18/**
19* Database Abstraction Layer
20*/
21class factory implements driver_interface
22{
23	/**
24	* @var driver_interface
25	*/
26	protected $driver = null;
27
28	/**
29	* @var ContainerInterface
30	*/
31	protected $container;
32
33	/**
34	* Constructor.
35	*
36	* @param ContainerInterface $container A ContainerInterface instance
37	*/
38	public function __construct(ContainerInterface $container)
39	{
40		$this->container = $container;
41	}
42
43	/**
44	* Return the current driver (and retrieved it from the container if necessary)
45	*
46	* @return driver_interface
47	*/
48	protected function get_driver()
49	{
50		if ($this->driver === null)
51		{
52			$this->driver = $this->container->get('dbal.conn.driver');
53		}
54
55		return $this->driver;
56	}
57
58	/**
59	* Set the current driver
60	*
61	* @param driver_interface $driver
62	*/
63	public function set_driver(driver_interface $driver)
64	{
65		$this->driver = $driver;
66	}
67
68	/**
69	* {@inheritdoc}
70	*/
71	public function set_debug_load_time($value)
72	{
73		$this->get_driver()->set_debug_load_time($value);
74	}
75
76	/**
77	* {@inheritdoc}
78	*/
79	public function set_debug_sql_explain($value)
80	{
81		$this->get_driver()->set_debug_sql_explain($value);
82	}
83
84	/**
85	* {@inheritdoc}
86	*/
87	public function get_sql_layer()
88	{
89		return $this->get_driver()->get_sql_layer();
90	}
91
92	/**
93	* {@inheritdoc}
94	*/
95	public function get_db_name()
96	{
97		return $this->get_driver()->get_db_name();
98	}
99
100	/**
101	* {@inheritdoc}
102	*/
103	public function get_any_char()
104	{
105		return $this->get_driver()->get_any_char();
106	}
107
108	/**
109	* {@inheritdoc}
110	*/
111	public function get_one_char()
112	{
113		return $this->get_driver()->get_one_char();
114	}
115
116	/**
117	* {@inheritdoc}
118	*/
119	public function get_db_connect_id()
120	{
121		return $this->get_driver()->get_db_connect_id();
122	}
123
124	/**
125	* {@inheritdoc}
126	*/
127	public function get_sql_error_triggered()
128	{
129		return $this->get_driver()->get_sql_error_triggered();
130	}
131
132	/**
133	* {@inheritdoc}
134	*/
135	public function get_sql_error_sql()
136	{
137		return $this->get_driver()->get_sql_error_sql();
138	}
139
140	/**
141	* {@inheritdoc}
142	*/
143	public function get_transaction()
144	{
145		return $this->get_driver()->get_transaction();
146	}
147
148	/**
149	* {@inheritdoc}
150	*/
151	public function get_sql_time()
152	{
153		return $this->get_driver()->get_sql_time();
154	}
155
156	/**
157	* {@inheritdoc}
158	*/
159	public function get_sql_error_returned()
160	{
161		return $this->get_driver()->get_sql_error_returned();
162	}
163
164	/**
165	* {@inheritdoc}
166	*/
167	public function get_multi_insert()
168	{
169		return $this->get_driver()->get_multi_insert();
170	}
171
172	/**
173	* {@inheritdoc}
174	*/
175	public function set_multi_insert($multi_insert)
176	{
177		$this->get_driver()->set_multi_insert($multi_insert);
178	}
179
180	/**
181	* {@inheritdoc}
182	*/
183	public function get_row_count($table_name)
184	{
185		return $this->get_driver()->get_row_count($table_name);
186	}
187
188	/**
189	* {@inheritdoc}
190	*/
191	public function get_estimated_row_count($table_name)
192	{
193		return $this->get_driver()->get_estimated_row_count($table_name);
194	}
195
196	/**
197	* {@inheritdoc}
198	*/
199	public function sql_lower_text($column_name)
200	{
201		return $this->get_driver()->sql_lower_text($column_name);
202	}
203
204	/**
205	* {@inheritdoc}
206	*/
207	public function sql_error($sql = '')
208	{
209		return $this->get_driver()->sql_error($sql);
210	}
211
212	/**
213	* {@inheritdoc}
214	*/
215	public function sql_buffer_nested_transactions()
216	{
217		return $this->get_driver()->sql_buffer_nested_transactions();
218	}
219
220	/**
221	* {@inheritdoc}
222	*/
223	public function sql_bit_or($column_name, $bit, $compare = '')
224	{
225		return $this->get_driver()->sql_bit_or($column_name, $bit, $compare);
226	}
227
228	/**
229	* {@inheritdoc}
230	*/
231	public function sql_server_info($raw = false, $use_cache = true)
232	{
233		return $this->get_driver()->sql_server_info($raw, $use_cache);
234	}
235
236	/**
237	* {@inheritdoc}
238	*/
239	public function sql_return_on_error($fail = false)
240	{
241		return $this->get_driver()->sql_return_on_error($fail);
242	}
243
244	/**
245	* {@inheritdoc}
246	*/
247	public function sql_build_array($query, $assoc_ary = array())
248	{
249		return $this->get_driver()->sql_build_array($query, $assoc_ary);
250	}
251
252	/**
253	* {@inheritdoc}
254	*/
255	public function sql_fetchrowset($query_id = false)
256	{
257		return $this->get_driver()->sql_fetchrowset($query_id);
258	}
259
260	/**
261	* {@inheritdoc}
262	*/
263	public function sql_transaction($status = 'begin')
264	{
265		return $this->get_driver()->sql_transaction($status);
266	}
267
268	/**
269	* {@inheritdoc}
270	*/
271	public function sql_concatenate($expr1, $expr2)
272	{
273		return $this->get_driver()->sql_concatenate($expr1, $expr2);
274	}
275
276	/**
277	* {@inheritdoc}
278	*/
279	public function sql_case($condition, $action_true, $action_false = false)
280	{
281		return $this->get_driver()->sql_case($condition, $action_true, $action_false);
282	}
283
284	/**
285	* {@inheritdoc}
286	*/
287	public function sql_build_query($query, $array)
288	{
289		return $this->get_driver()->sql_build_query($query, $array);
290	}
291
292	/**
293	* {@inheritdoc}
294	*/
295	public function sql_fetchfield($field, $rownum = false, $query_id = false)
296	{
297		return $this->get_driver()->sql_fetchfield($field, $rownum, $query_id);
298	}
299
300	/**
301	* {@inheritdoc}
302	*/
303	public function sql_fetchrow($query_id = false)
304	{
305		return $this->get_driver()->sql_fetchrow($query_id);
306	}
307
308	/**
309	* {@inheritdoc}
310	*/
311	public function cast_expr_to_bigint($expression)
312	{
313		return $this->get_driver()->cast_expr_to_bigint($expression);
314	}
315
316	/**
317	* {@inheritdoc}
318	*/
319	public function sql_nextid()
320	{
321		return $this->get_driver()->sql_nextid();
322	}
323
324	/**
325	* {@inheritdoc}
326	*/
327	public function sql_add_num_queries($cached = false)
328	{
329		return $this->get_driver()->sql_add_num_queries($cached);
330	}
331
332	/**
333	* {@inheritdoc}
334	*/
335	public function sql_query_limit($query, $total, $offset = 0, $cache_ttl = 0)
336	{
337		return $this->get_driver()->sql_query_limit($query, $total, $offset, $cache_ttl);
338	}
339
340	/**
341	* {@inheritdoc}
342	*/
343	public function sql_query($query = '', $cache_ttl = 0)
344	{
345		return $this->get_driver()->sql_query($query, $cache_ttl);
346	}
347
348	/**
349	* {@inheritdoc}
350	*/
351	public function cast_expr_to_string($expression)
352	{
353		return $this->get_driver()->cast_expr_to_string($expression);
354	}
355
356	/**
357	* {@inheritdoc}
358	*/
359	public function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
360	{
361		throw new \Exception('Disabled method.');
362	}
363
364	/**
365	* {@inheritdoc}
366	*/
367	public function sql_bit_and($column_name, $bit, $compare = '')
368	{
369		return $this->get_driver()->sql_bit_and($column_name, $bit, $compare);
370	}
371
372	/**
373	* {@inheritdoc}
374	*/
375	public function sql_freeresult($query_id = false)
376	{
377		return $this->get_driver()->sql_freeresult($query_id);
378	}
379
380	/**
381	* {@inheritdoc}
382	*/
383	public function sql_num_queries($cached = false)
384	{
385		return $this->get_driver()->sql_num_queries($cached);
386	}
387
388	/**
389	* {@inheritdoc}
390	*/
391	public function sql_multi_insert($table, $sql_ary)
392	{
393		return $this->get_driver()->sql_multi_insert($table, $sql_ary);
394	}
395
396	/**
397	* {@inheritdoc}
398	*/
399	public function sql_affectedrows()
400	{
401		return $this->get_driver()->sql_affectedrows();
402	}
403
404	/**
405	* {@inheritdoc}
406	*/
407	public function sql_close()
408	{
409		return $this->get_driver()->sql_close();
410	}
411
412	/**
413	* {@inheritdoc}
414	*/
415	public function sql_rowseek($rownum, &$query_id)
416	{
417		return $this->get_driver()->sql_rowseek($rownum, $query_id);
418	}
419
420	/**
421	* {@inheritdoc}
422	*/
423	public function sql_escape($msg)
424	{
425		return $this->get_driver()->sql_escape($msg);
426	}
427
428	/**
429	* {@inheritdoc}
430	*/
431	public function sql_like_expression($expression)
432	{
433		return $this->get_driver()->sql_like_expression($expression);
434	}
435
436	/**
437	* {@inheritdoc}
438	*/
439	public function sql_not_like_expression($expression)
440	{
441		return $this->get_driver()->sql_not_like_expression($expression);
442	}
443
444	/**
445	* {@inheritdoc}
446	*/
447	public function sql_report($mode, $query = '')
448	{
449		return $this->get_driver()->sql_report($mode, $query);
450	}
451
452	/**
453	* {@inheritdoc}
454	*/
455	public function sql_in_set($field, $array, $negate = false, $allow_empty_set = false)
456	{
457		return $this->get_driver()->sql_in_set($field, $array, $negate, $allow_empty_set);
458	}
459
460	/**
461	* {@inheritdoc}
462	*/
463	public function sql_quote($msg)
464	{
465		return $this->get_driver()->sql_quote($msg);
466	}
467}
468