-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueryBuilderFactory.php
More file actions
50 lines (40 loc) · 1.27 KB
/
QueryBuilderFactory.php
File metadata and controls
50 lines (40 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
/*
* Studio 107 (c) 2018 Maxim Falaleev
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mindy\QueryBuilder;
use Doctrine\DBAL\Connection;
use Mindy\QueryBuilder\Exception\NotSupportedException;
class QueryBuilderFactory
{
/**
* @param Connection $connection
*
* @throws NotSupportedException
*
* @return QueryBuilder
*/
public static function getQueryBuilder(Connection $connection)
{
switch ($connection->getDriver()->getName()) {
case 'pdo_mysql':
$adapter = new Database\Mysql\Adapter($connection);
break;
case 'pdo_sqlite':
$adapter = new Database\Sqlite\Adapter($connection);
break;
case 'pdo_pgsql':
$adapter = new Database\Pgsql\Adapter($connection);
break;
default:
throw new NotSupportedException('Unknown driver');
}
$lookupBuilder = new LookupBuilder();
$lookupBuilder->addLookupCollection($adapter->getLookupCollection());
return new QueryBuilder($connection, $adapter, $lookupBuilder);
}
}