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; |
13
|
|
|
|
14
|
|
|
use Phuria\SQLBuilder\DependencyInjection\ContainerFactory; |
15
|
|
|
use Phuria\SQLBuilder\QueryBuilder\DeleteBuilder; |
16
|
|
|
use Phuria\SQLBuilder\QueryBuilder\InsertBuilder; |
17
|
|
|
use Phuria\SQLBuilder\QueryBuilder\InsertSelectBuilder; |
18
|
|
|
use Phuria\SQLBuilder\QueryBuilder\SelectBuilder; |
19
|
|
|
use Phuria\SQLBuilder\QueryBuilder\UpdateBuilder; |
20
|
|
|
use Phuria\SQLBuilder\QueryCompiler\QueryCompilerInterface; |
21
|
|
|
use Pimple\Container; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class QueryBuilderFactory |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var Container $container |
30
|
|
|
*/ |
31
|
|
|
private $container; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param Container|null $container |
35
|
|
|
*/ |
36
|
6 |
|
public function __construct(Container $container = null) |
37
|
|
|
{ |
38
|
6 |
|
$this->container = $container ?: (new ContainerFactory())->create(); |
39
|
6 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return Container |
43
|
|
|
*/ |
44
|
6 |
|
public function getContainer() |
45
|
|
|
{ |
46
|
6 |
|
return $this->container; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $class |
51
|
|
|
* |
52
|
|
|
* @return QueryCompilerInterface |
53
|
|
|
*/ |
54
|
35 |
|
private function createQueryBuilder($class) |
55
|
|
|
{ |
56
|
35 |
|
$parameterClass = $this->container['phuria.sql_builder.parameter_manager.class']; |
57
|
|
|
|
58
|
35 |
|
return new $class( |
59
|
35 |
|
$this->container['phuria.sql_builder.table_factory'], |
60
|
35 |
|
$this->container['phuria.sql_builder.query_compiler'], |
61
|
|
|
new $parameterClass |
62
|
35 |
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return SelectBuilder |
|
|
|
|
67
|
|
|
*/ |
68
|
26 |
|
public function createSelect() |
69
|
|
|
{ |
70
|
26 |
|
return $this->createQueryBuilder(SelectBuilder::class); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return UpdateBuilder |
|
|
|
|
75
|
|
|
*/ |
76
|
4 |
|
public function createUpdate() |
77
|
|
|
{ |
78
|
4 |
|
return $this->createQueryBuilder(UpdateBuilder::class); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return DeleteBuilder |
|
|
|
|
83
|
|
|
*/ |
84
|
3 |
|
public function createDelete() |
85
|
|
|
{ |
86
|
3 |
|
return $this->createQueryBuilder(DeleteBuilder::class); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return InsertBuilder |
|
|
|
|
91
|
|
|
*/ |
92
|
2 |
|
public function createInsert() |
93
|
|
|
{ |
94
|
2 |
|
return $this->createQueryBuilder(InsertBuilder::class); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return InsertSelectBuilder |
|
|
|
|
99
|
|
|
*/ |
100
|
6 |
|
public function createInsertSelect() |
101
|
|
|
{ |
102
|
6 |
|
return $this->createQueryBuilder(InsertSelectBuilder::class); |
103
|
|
|
} |
104
|
|
|
} |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.