Completed
Push — master ( ad3a38...ce24f7 )
by Beniamin
02:38
created

ContainerFactory::createTableCompiler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
crap 1
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\Connection\ConnectionManager;
15
use Phuria\SQLBuilder\Parameter\ParameterManager;
16
use Phuria\SQLBuilder\Query\QueryFactory;
17
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\DeleteCompiler;
18
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\InsertCompiler;
19
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\SelectCompiler;
20
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\UpdateCompiler;
21
use Phuria\SQLBuilder\QueryCompiler\QueryCompiler;
22
use Phuria\SQLBuilder\TableFactory\TableFactory;
23
use Phuria\SQLBuilder\TableRegistry;
24
use Pimple\Container;
25
26
/**
27
 * @author Beniamin Jonatan Šimko <[email protected]>
28
 */
29
class ContainerFactory
30
{
31
    /**
32
     * @return Container
33
     */
34 36
    public function create()
35
    {
36 36
        $container = new Container();
37
38 36
        $container['phuria.sql_builder.parameter_manager.class'] = ParameterManager::class;
39
40 36
        $container['phuria.sql_builder.table_registry'] = new InvokeCallback([
41 36
            $this, 'createTableRegistry'
42 36
        ]);
43
44 36
        $container['phuria.sql_builder.table_factory'] = new InvokeCallback([
45 36
            $this, 'createTableFactory'
46 36
        ]);
47
48 36
        $container['phuria.sql_builder.query_compiler'] = new InvokeCallback([
49 36
            $this, 'createTableCompiler'
50 36
        ]);
51
52 36
        $container['phuria.sql_builder.connection_manager'] = new InvokeCallback([
53 36
            $this, 'createConnectionManager'
54 36
        ]);
55
56 36
        $container['phuria.sql_builder.query_factory'] = new InvokeCallback([
57 36
            $this, 'createQueryFactory'
58 36
        ]);
59
60 36
        return $container;
61
    }
62
63
    /**
64
     * @return TableRegistry
65
     */
66 36
    public function createTableRegistry()
67
    {
68 36
        return new TableRegistry();
69
    }
70
71
    /**
72
     * @param Container $container
73
     *
74
     * @return TableFactory
75
     */
76 36
    public function createTableFactory(Container $container)
77
    {
78 36
        return new TableFactory($container['phuria.sql_builder.table_registry']);
79
    }
80
81
    /**
82
     * @return QueryCompiler
83
     */
84 36
    public function createTableCompiler()
85
    {
86 36
        $queryCompiler = new QueryCompiler();
87 36
        $queryCompiler->addConcreteCompiler(new SelectCompiler());
88 36
        $queryCompiler->addConcreteCompiler(new InsertCompiler());
89 36
        $queryCompiler->addConcreteCompiler(new DeleteCompiler());
90 36
        $queryCompiler->addConcreteCompiler(new UpdateCompiler());
91
92 36
        return $queryCompiler;
93
    }
94
95
    /**
96
     * @return ConnectionManager
97
     */
98 36
    public function createConnectionManager()
99
    {
100 36
        return new ConnectionManager();
101
    }
102
103
    /**
104
     * @param Container $container
105
     *
106
     * @return QueryFactory
107
     */
108 36
    public function createQueryFactory(Container $container)
109
    {
110 36
        return new QueryFactory($container['phuria.sql_builder.connection_manager']);
111
    }
112
}