Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
factory
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 2
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 get
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
42
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\extractor;
15
16/**
17* A factory which serves the suitable extractor instance for the given dbal
18*/
19class factory
20{
21    /**
22     * @var \phpbb\db\driver\driver_interface
23     */
24    protected $db;
25
26    /**
27     * @var \Symfony\Component\DependencyInjection\ContainerInterface
28     */
29    protected $container;
30
31    /**
32    * Extractor factory constructor
33    *
34    * @param \phpbb\db\driver\driver_interface                            $db
35    * @param \Symfony\Component\DependencyInjection\ContainerInterface    $container
36    */
37    public function __construct(\phpbb\db\driver\driver_interface $db, \Symfony\Component\DependencyInjection\ContainerInterface $container)
38    {
39        $this->db            = $db;
40        $this->container    = $container;
41    }
42
43    /**
44    * DB extractor factory getter
45    *
46    * @return \phpbb\db\extractor\extractor_interface an appropriate instance of the database extractor for the used database driver
47    * @throws \InvalidArgumentException when the database driver is unknown
48    */
49    public function get()
50    {
51        // Return the appropriate DB extractor
52        if ($this->db instanceof \phpbb\db\driver\mssql_base)
53        {
54            $extractor = $this->container->get('dbal.extractor.extractors.mssql_extractor');
55        }
56        else if ($this->db instanceof \phpbb\db\driver\mysql_base)
57        {
58            $extractor = $this->container->get('dbal.extractor.extractors.mysql_extractor');
59        }
60        else if ($this->db instanceof \phpbb\db\driver\oracle)
61        {
62            $extractor = $this->container->get('dbal.extractor.extractors.oracle_extractor');
63        }
64        else if ($this->db instanceof \phpbb\db\driver\postgres)
65        {
66            $extractor = $this->container->get('dbal.extractor.extractors.postgres_extractor');
67        }
68        else if ($this->db instanceof \phpbb\db\driver\sqlite3)
69        {
70            $extractor = $this->container->get('dbal.extractor.extractors.sqlite3_extractor');
71        }
72        else
73        {
74            throw new \InvalidArgumentException('Invalid database driver given');
75        }
76
77        /** @var \phpbb\db\extractor\extractor_interface $extractor */
78        return $extractor;
79    }
80}