1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of UnderQuery package. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016 Beniamin Jonatan Šimko |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Phuria\UnderQuery\QueryBuilder; |
13
|
|
|
|
14
|
|
|
use Doctrine\DBAL\Driver\Connection as ConnectionInterface; |
15
|
|
|
use Phuria\UnderQuery\QueryCompiler\QueryCompilerInterface; |
16
|
|
|
use Phuria\UnderQuery\Table\AbstractTable; |
17
|
|
|
use Phuria\UnderQuery\TableFactory\TableFactoryInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class QueryBuilderFacade |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var TableFactoryInterface |
26
|
|
|
*/ |
27
|
|
|
private $tableFactory; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var QueryCompilerInterface |
31
|
|
|
*/ |
32
|
|
|
private $queryCompiler; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var ConnectionInterface|null |
36
|
|
|
*/ |
37
|
|
|
private $connection; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param TableFactoryInterface $tableFactory |
41
|
|
|
* @param QueryCompilerInterface $queryCompiler |
42
|
|
|
* @param ConnectionInterface|null $connection |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
TableFactoryInterface $tableFactory, |
46
|
|
|
QueryCompilerInterface $queryCompiler, |
47
|
|
|
ConnectionInterface $connection = null |
48
|
|
|
) { |
49
|
|
|
$this->tableFactory = $tableFactory; |
50
|
|
|
$this->queryCompiler = $queryCompiler; |
51
|
|
|
$this->connection = $connection; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param mixed $builder |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function buildSQL($builder) |
60
|
|
|
{ |
61
|
|
|
return $this->queryCompiler->compile($builder); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param mixed $builder |
66
|
|
|
* @param mixed $table |
67
|
|
|
* |
68
|
|
|
* @return AbstractTable |
69
|
|
|
*/ |
70
|
|
|
public function createTable($builder, $table) |
71
|
|
|
{ |
72
|
|
|
return $this->tableFactory->createNewTable($table, $builder); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return ConnectionInterface|null |
77
|
|
|
*/ |
78
|
|
|
public function getConnection() |
79
|
|
|
{ |
80
|
|
|
return $this->connection; |
81
|
|
|
} |
82
|
|
|
} |