Completed
Push — master ( 87ad62...d12792 )
by Beniamin
03:02
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 Interop\Container\ContainerInterface;
15
use Phuria\SQLBuilder\Connection\ConnectionManager;
16
use Phuria\SQLBuilder\Parameter\ParameterManager;
17
use Phuria\SQLBuilder\Query\QueryFactory;
18
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\DeleteCompiler;
19
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\InsertCompiler;
20
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\SelectCompiler;
21
use Phuria\SQLBuilder\QueryCompiler\ConcreteCompiler\UpdateCompiler;
22
use Phuria\SQLBuilder\QueryCompiler\QueryCompiler;
23
use Phuria\SQLBuilder\TableFactory\TableFactory;
24
use Phuria\SQLBuilder\TableRegistry;
25
use Pimple\Container;
26
27
/**
28
 * @author Beniamin Jonatan Šimko <[email protected]>
29
 */
30
class ContainerFactory
31
{
32
    /**
33
     * @return ContainerInterface
34
     */
35 2
    public function create()
36
    {
37 2
        $pimple = new Container();
38 2
        $container = new PimpleContainer($pimple);
39
40 2
        $container->setParameter('phuria.sql_builder.parameter_manager.class', ParameterManager::class);
41
42 2
        $container->setServiceFromCallback('phuria.sql_builder.table_registry', [$this, 'createTableRegistry']);
43 2
        $container->setServiceFromCallback('phuria.sql_builder.table_factory', [$this, 'createTableFactory']);
44 2
        $container->setServiceFromCallback('phuria.sql_builder.query_compiler', [$this, 'createTableCompiler']);
45 2
        $container->setServiceFromCallback('phuria.sql_builder.connection_manager', [$this, 'createConnectionManager']);
46 2
        $container->setServiceFromCallback('phuria.sql_builder.query_factory', [$this, 'createQueryFactory']);
47
48 2
        return $container;
49
    }
50
51
    /**
52
     * @internal
53
     * @return TableRegistry
54
     */
55 1
    public function createTableRegistry()
56
    {
57 1
        return new TableRegistry();
58
    }
59
60
    /**
61
     * @internal
62
     * @param Container $container
63
     *
64
     * @return TableFactory
65
     */
66 1
    public function createTableFactory(Container $container)
67
    {
68 1
        return new TableFactory($container['phuria.sql_builder.table_registry']);
69
    }
70
71
    /**
72
     * @internal
73
     * @return QueryCompiler
74
     */
75 1
    public function createTableCompiler()
76
    {
77 1
        $queryCompiler = new QueryCompiler();
78 1
        $queryCompiler->addConcreteCompiler(new SelectCompiler());
79 1
        $queryCompiler->addConcreteCompiler(new InsertCompiler());
80 1
        $queryCompiler->addConcreteCompiler(new DeleteCompiler());
81 1
        $queryCompiler->addConcreteCompiler(new UpdateCompiler());
82
83 1
        return $queryCompiler;
84
    }
85
86
    /**
87
     * @internal
88
     * @return ConnectionManager
89
     */
90 1
    public function createConnectionManager()
91
    {
92 1
        return new ConnectionManager();
93
    }
94
95
    /**
96
     * @internal
97
     * @param Container $container
98
     *
99
     * @return QueryFactory
100
     */
101 1
    public function createQueryFactory(Container $container)
102
    {
103 1
        return new QueryFactory($container['phuria.sql_builder.connection_manager']);
104
    }
105
}