diff options
| author | MateBartus <mate.bartus@gmail.com> | 2015-02-22 16:22:10 +0100 |
|---|---|---|
| committer | MateBartus <mate.bartus@gmail.com> | 2015-02-27 16:18:50 +0100 |
| commit | 193c5b86b4b6049a9bf5abc5251d5479493a10df (patch) | |
| tree | 9d9c817c5f10dbf47ad0d44ff37ab6c512a38f66 /phpBB/phpbb/db/extractor/factory.php | |
| parent | 3657d7a85a5489f55ced17326064e63924303928 (diff) | |
| download | forums-193c5b86b4b6049a9bf5abc5251d5479493a10df.tar forums-193c5b86b4b6049a9bf5abc5251d5479493a10df.tar.gz forums-193c5b86b4b6049a9bf5abc5251d5479493a10df.tar.bz2 forums-193c5b86b4b6049a9bf5abc5251d5479493a10df.tar.xz forums-193c5b86b4b6049a9bf5abc5251d5479493a10df.zip | |
[ticket/12466] Move classes from acp_database.php to their own files
* Moving classes from acp_database.php to phpbb/db/extractor namespace,
also into separate files
* Adding DocBlocks and property visibility to classes
* Removing globals from code
* Passing former globals to base_extractor's constructor
* Adding DB extractor as a service, also implementing the extractor interface
as well as the extractor factory.
PHPBB3-12466
Diffstat (limited to 'phpBB/phpbb/db/extractor/factory.php')
| -rw-r--r-- | phpBB/phpbb/db/extractor/factory.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/phpBB/phpbb/db/extractor/factory.php b/phpBB/phpbb/db/extractor/factory.php new file mode 100644 index 0000000000..a1ffb65595 --- /dev/null +++ b/phpBB/phpbb/db/extractor/factory.php @@ -0,0 +1,79 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\db\extractor; + +/** +* A factory which serves the suitable extractor instance for the given dbal +*/ +class factory +{ + /** + * @var \phpbb\db\driver\driver_interface + */ + protected $db; + + /** + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + + /** + * Extractor factory constructor + * + * @param \phpbb\db\driver\driver_interface $db + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + */ + public function __construct(\phpbb\db\driver\driver_interface $db, \Symfony\Component\DependencyInjection\ContainerInterface $container) + { + $this->db = $db; + $this->container = $container; + } + + /** + * DB extractor factory getter + * + * @return \phpbb\db\extractor\extractor_interface an appropriate instance of the database extractor for the used database driver + * @throws \InvalidArgumentException when the database driver is unknown + */ + public function get() + { + // Return the appropriate DB extractor + if ($this->db instanceof \phpbb\db\driver\mssql || $this->db instanceof \phpbb\db\driver\mssql_base) + { + return $this->container->get('dbal.extractor.extractors.mssql_extractor'); + } + else if ($this->db instanceof \phpbb\db\driver\mysql_base) + { + return $this->container->get('dbal.extractor.extractors.mysql_extractor'); + } + else if ($this->db instanceof \phpbb\db\driver\oracle) + { + return $this->container->get('dbal.extractor.extractors.oracle_extractor'); + } + else if ($this->db instanceof \phpbb\db\driver\postgres) + { + return $this->container->get('dbal.extractor.extractors.postgres_extractor'); + } + else if ($this->db instanceof \phpbb\db\driver\sqlite) + { + return $this->container->get('dbal.extractor.extractors.sqlite_extractor'); + } + else if ($this->db instanceof \phpbb\db\driver\sqlite3) + { + return $this->container->get('dbal.extractor.extractors.sqlite3_extractor'); + } + + throw new \InvalidArgumentException('Invalid database driver given'); + } +} |
