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 Phuria\UnderQuery\Connection\ConnectionInterface; |
15
|
|
|
use Phuria\UnderQuery\QueryCompiler\QueryCompilerInterface; |
16
|
|
|
use Phuria\UnderQuery\Statement\StatementInterface; |
17
|
|
|
use Phuria\UnderQuery\Table\AbstractTable; |
18
|
|
|
use Phuria\UnderQuery\TableFactory\TableFactoryInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class QueryBuilderFacade |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var TableFactoryInterface |
27
|
|
|
*/ |
28
|
|
|
private $tableFactory; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var QueryCompilerInterface |
32
|
|
|
*/ |
33
|
|
|
private $queryCompiler; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var ConnectionInterface |
37
|
|
|
*/ |
38
|
|
|
private $connection; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param TableFactoryInterface $tableFactory |
42
|
|
|
* @param QueryCompilerInterface $queryCompiler |
43
|
|
|
* @param ConnectionInterface|null $connection |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
TableFactoryInterface $tableFactory, |
47
|
|
|
QueryCompilerInterface $queryCompiler, |
48
|
|
|
ConnectionInterface $connection = null |
49
|
|
|
) { |
50
|
|
|
$this->tableFactory = $tableFactory; |
51
|
|
|
$this->queryCompiler = $queryCompiler; |
52
|
|
|
$this->connection = $connection; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param mixed $builder |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function buildSQL($builder) |
61
|
|
|
{ |
62
|
|
|
return $this->queryCompiler->compile($builder); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param string $compiledSQL |
67
|
|
|
* @param array $parameters |
68
|
|
|
* |
69
|
|
|
* @return StatementInterface |
70
|
|
|
*/ |
71
|
|
|
public function buildStatement($compiledSQL, array $parameters) |
72
|
|
|
{ |
73
|
|
|
return $this->connection->prepareStatement($compiledSQL, $parameters); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param mixed $builder |
78
|
|
|
* @param mixed $table |
79
|
|
|
* |
80
|
|
|
* @return AbstractTable |
81
|
|
|
*/ |
82
|
|
|
public function createTable($builder, $table) |
83
|
|
|
{ |
84
|
|
|
return $this->tableFactory->createNewTable($table, $builder); |
85
|
|
|
} |
86
|
|
|
} |