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\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Phuria\SQLBuilder\Parameter\ParameterManager; |
15
|
|
|
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\DeleteCompiler; |
16
|
|
|
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\InsertCompiler; |
17
|
|
|
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\SelectCompiler; |
18
|
|
|
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\UpdateCompiler; |
19
|
|
|
use Phuria\SQLBuilder\QueryCompiler\QueryCompiler; |
20
|
|
|
use Phuria\SQLBuilder\TableFactory\TableFactory; |
21
|
|
|
use Phuria\SQLBuilder\TableRegistry; |
22
|
|
|
use Pimple\Container; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class ContainerFactory |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @return Container |
31
|
|
|
*/ |
32
|
6 |
|
public function create() |
33
|
|
|
{ |
34
|
6 |
|
$container = new Container(); |
35
|
|
|
|
36
|
6 |
|
$container['phuria.sql_builder.parameter_manager.class'] = ParameterManager::class; |
37
|
|
|
|
38
|
6 |
|
$container['phuria.sql_builder.table_registry'] = new InvokeCallback( |
39
|
6 |
|
[$this, 'createTableRegistry'] |
40
|
6 |
|
); |
41
|
|
|
|
42
|
6 |
|
$container['phuria.sql_builder.table_factory'] = new InvokeCallback( |
43
|
6 |
|
[$this, 'createTableFactory'] |
44
|
6 |
|
); |
45
|
|
|
|
46
|
6 |
|
$container['phuria.sql_builder.query_compiler'] = new InvokeCallback( |
47
|
6 |
|
[$this, 'createTableCompiler'] |
48
|
6 |
|
); |
49
|
|
|
|
50
|
6 |
|
return $container; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return TableRegistry |
55
|
|
|
*/ |
56
|
6 |
|
public function createTableRegistry() |
57
|
|
|
{ |
58
|
6 |
|
return new TableRegistry(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param Container $container |
63
|
|
|
* |
64
|
|
|
* @return TableFactory |
65
|
|
|
*/ |
66
|
6 |
|
public function createTableFactory(Container $container) |
67
|
|
|
{ |
68
|
6 |
|
return new TableFactory($container['phuria.sql_builder.table_registry']); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return QueryCompiler |
73
|
|
|
*/ |
74
|
6 |
|
public function createTableCompiler() |
75
|
|
|
{ |
76
|
6 |
|
$queryCompiler = new QueryCompiler(); |
77
|
6 |
|
$queryCompiler->addConcreteCompiler(new SelectCompiler()); |
78
|
6 |
|
$queryCompiler->addConcreteCompiler(new InsertCompiler()); |
79
|
6 |
|
$queryCompiler->addConcreteCompiler(new DeleteCompiler()); |
80
|
6 |
|
$queryCompiler->addConcreteCompiler(new UpdateCompiler()); |
81
|
|
|
|
82
|
6 |
|
return $queryCompiler; |
83
|
|
|
} |
84
|
|
|
} |