Completed
Push — master ( 7623c5...923419 )
by Beniamin
04:53
created

ContainerFactory::create()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 26
ccs 13
cts 13
cp 1
rs 8.8571
cc 1
eloc 15
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\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
        $container['phuria.sql_builder.table_registry'] = function () {
39 6
            return new TableRegistry();
40
        };
41
42
        $container['phuria.sql_builder.table_factory'] = function (Container $c) {
43 6
            return new TableFactory($c['phuria.sql_builder.table_registry']);
44
        };
45
46 6
        $container['phuria.sql_builder.query_compiler'] = function () {
47 6
            $queryCompiler = new QueryCompiler();
48 6
            $queryCompiler->addConcreteCompiler(new SelectCompiler());
49 6
            $queryCompiler->addConcreteCompiler(new InsertCompiler());
50 6
            $queryCompiler->addConcreteCompiler(new DeleteCompiler());
51 6
            $queryCompiler->addConcreteCompiler(new UpdateCompiler());
52
53 6
            return $queryCompiler;
54
        };
55
56 6
        return $container;
57
    }
58
}