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; |
13
|
|
|
|
14
|
|
|
use Interop\Container\ContainerInterface; |
15
|
|
|
use Phuria\UnderQuery\Connection\ConnectionInterface; |
16
|
|
|
use Phuria\UnderQuery\DependencyInjection\ContainerFactory; |
17
|
|
|
use Phuria\UnderQuery\QueryBuilder\DeleteBuilder; |
18
|
|
|
use Phuria\UnderQuery\QueryBuilder\InsertBuilder; |
19
|
|
|
use Phuria\UnderQuery\QueryBuilder\InsertSelectBuilder; |
20
|
|
|
use Phuria\UnderQuery\QueryBuilder\QueryBuilderFacade; |
21
|
|
|
use Phuria\UnderQuery\QueryBuilder\SelectBuilder; |
22
|
|
|
use Phuria\UnderQuery\QueryBuilder\UpdateBuilder; |
23
|
|
|
use Phuria\UnderQuery\QueryCompiler\QueryCompilerInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class UnderQuery |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var ContainerInterface |
32
|
|
|
*/ |
33
|
|
|
private $container; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var ConnectionInterface|null |
37
|
|
|
*/ |
38
|
|
|
private $connection; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param ConnectionInterface|null $connection |
42
|
|
|
* @param ContainerInterface|null $container |
43
|
|
|
*/ |
44
|
2 |
|
public function __construct(ConnectionInterface $connection = null, ContainerInterface $container = null) |
45
|
|
|
{ |
46
|
2 |
|
$this->container = $container ?: (new ContainerFactory())->create(); |
47
|
2 |
|
$this->connection = $connection; |
48
|
2 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return ContainerInterface |
52
|
|
|
*/ |
53
|
2 |
|
public function getContainer() |
54
|
|
|
{ |
55
|
2 |
|
return $this->container; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return null|ConnectionInterface |
60
|
|
|
*/ |
61
|
|
|
public function getConnection() |
62
|
|
|
{ |
63
|
|
|
return $this->connection; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $class |
68
|
|
|
* |
69
|
|
|
* @return QueryCompilerInterface |
70
|
|
|
*/ |
71
|
1 |
|
private function createQueryBuilder($class) |
72
|
|
|
{ |
73
|
1 |
|
return new $class(new QueryBuilderFacade( |
74
|
1 |
|
$this->getContainer()->get('phuria.under_query.table_factory'), |
75
|
1 |
|
$this->getContainer()->get('phuria.under_query.query_compiler'), |
76
|
1 |
|
$this->connection |
77
|
1 |
|
)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return SelectBuilder |
|
|
|
|
82
|
|
|
*/ |
83
|
1 |
|
public function createSelect() |
84
|
|
|
{ |
85
|
1 |
|
return $this->createQueryBuilder(SelectBuilder::class); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return UpdateBuilder |
|
|
|
|
90
|
|
|
*/ |
91
|
1 |
|
public function createUpdate() |
92
|
|
|
{ |
93
|
1 |
|
return $this->createQueryBuilder(UpdateBuilder::class); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return DeleteBuilder |
|
|
|
|
98
|
|
|
*/ |
99
|
1 |
|
public function createDelete() |
100
|
|
|
{ |
101
|
1 |
|
return $this->createQueryBuilder(DeleteBuilder::class); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return InsertBuilder |
|
|
|
|
106
|
|
|
*/ |
107
|
1 |
|
public function createInsert() |
108
|
|
|
{ |
109
|
1 |
|
return $this->createQueryBuilder(InsertBuilder::class); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return InsertSelectBuilder |
|
|
|
|
114
|
|
|
*/ |
115
|
1 |
|
public function createInsertSelect() |
116
|
|
|
{ |
117
|
1 |
|
return $this->createQueryBuilder(InsertSelectBuilder::class); |
118
|
|
|
} |
119
|
|
|
} |
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.