1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Phuria SQL Builder 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\SQLBuilder\QueryBuilder; |
13
|
|
|
|
14
|
|
|
use Phuria\SQLBuilder\Connection\ConnectionInterface; |
15
|
|
|
use Phuria\SQLBuilder\Parameter\ParameterManager; |
16
|
|
|
use Phuria\SQLBuilder\Parameter\ParameterManagerInterface; |
17
|
|
|
use Phuria\SQLBuilder\Query; |
18
|
|
|
use Phuria\SQLBuilder\QueryCompiler\QueryCompiler; |
19
|
|
|
use Phuria\SQLBuilder\QueryCompiler\QueryCompilerInterface; |
20
|
|
|
use Phuria\SQLBuilder\ReferenceManager; |
21
|
|
|
use Phuria\SQLBuilder\TableFactory\TableFactory; |
22
|
|
|
use Phuria\SQLBuilder\TableFactory\TableFactoryInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
abstract class AbstractBuilder implements BuilderInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var TableFactoryInterface |
31
|
|
|
*/ |
32
|
|
|
private $tableFactory; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var QueryCompilerInterface |
36
|
|
|
*/ |
37
|
|
|
private $queryCompiler; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var ParameterManagerInterface |
41
|
|
|
*/ |
42
|
|
|
private $parameterManager; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var ReferenceManager |
46
|
|
|
*/ |
47
|
|
|
private $referenceManager; |
48
|
|
|
|
49
|
37 |
|
public function __construct() |
50
|
|
|
{ |
51
|
37 |
|
$this->tableFactory = new TableFactory(); |
52
|
37 |
|
$this->queryCompiler = new QueryCompiler(); |
53
|
37 |
|
$this->parameterManager = new ParameterManager(); |
54
|
37 |
|
$this->referenceManager = new ReferenceManager(); |
55
|
37 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return BuilderInterface |
59
|
|
|
*/ |
60
|
34 |
|
public function getQueryBuilder() |
61
|
|
|
{ |
62
|
34 |
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return TableFactoryInterface |
67
|
|
|
*/ |
68
|
32 |
|
public function getTableFactory() |
69
|
|
|
{ |
70
|
32 |
|
return $this->tableFactory; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return QueryCompilerInterface |
75
|
|
|
*/ |
76
|
34 |
|
public function getQueryCompiler() |
77
|
|
|
{ |
78
|
34 |
|
return $this->queryCompiler; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return ParameterManagerInterface |
83
|
|
|
*/ |
84
|
13 |
|
public function getParameterManager() |
85
|
|
|
{ |
86
|
13 |
|
return $this->parameterManager; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return ReferenceManager |
91
|
|
|
*/ |
92
|
34 |
|
public function getReferenceManager() |
93
|
|
|
{ |
94
|
34 |
|
return $this->referenceManager; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @inheritdoc |
99
|
|
|
*/ |
100
|
34 |
|
public function buildSQL() |
101
|
|
|
{ |
102
|
34 |
|
return $this->getQueryCompiler()->compile($this->getQueryBuilder()); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @inheritdoc |
107
|
|
|
*/ |
108
|
22 |
|
public function objectToString($object) |
109
|
|
|
{ |
110
|
22 |
|
return $this->getReferenceManager()->register($object); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param ConnectionInterface $connection |
|
|
|
|
115
|
|
|
* |
116
|
|
|
* @return Query |
117
|
|
|
*/ |
118
|
13 |
|
public function buildQuery(ConnectionInterface $connection = null) |
119
|
|
|
{ |
120
|
13 |
|
return new Query( |
121
|
13 |
|
$this->buildSQL(), |
122
|
13 |
|
$this->getParameterManager(), |
123
|
|
|
$connection |
124
|
13 |
|
); |
125
|
|
|
} |
126
|
|
|
} |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.