Completed
Push — master ( 152a7c...c89027 )
by Beniamin
03:17
created

AbstractBuilder::setParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 2
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\QueryBuilder;
13
14
use Phuria\SQLBuilder\Parameter\ParameterManagerInterface;
15
use Phuria\SQLBuilder\Query\Query;
16
use Phuria\SQLBuilder\Query\QueryFactoryInterface;
17
use Phuria\SQLBuilder\QueryCompiler\QueryCompilerInterface;
18
use Phuria\SQLBuilder\TableFactory\TableFactoryInterface;
19
20
/**
21
 * @author Beniamin Jonatan Šimko <[email protected]>
22
 */
23
abstract class AbstractBuilder implements BuilderInterface
24
{
25
    /**
26
     * @var TableFactoryInterface
27
     */
28
    private $tableFactory;
29
30
    /**
31
     * @var QueryCompilerInterface
32
     */
33
    private $queryCompiler;
34
35
    /**
36
     * @var ParameterManagerInterface
37
     */
38
    private $parameterManager;
39
40
    /**
41
     * @var QueryFactoryInterface
42
     */
43
    private $queryFactory;
44
45
    /**
46
     * @param TableFactoryInterface     $tableFactory
47
     * @param QueryCompilerInterface    $queryCompiler
48
     * @param ParameterManagerInterface $parameterManager
49
     * @param QueryFactoryInterface     $queryFactory
50
     */
51 1
    public function __construct(
52
        TableFactoryInterface $tableFactory,
53
        QueryCompilerInterface $queryCompiler,
54
        ParameterManagerInterface $parameterManager,
55
        QueryFactoryInterface $queryFactory
56
    ) {
57 1
        $this->tableFactory = $tableFactory;
58 1
        $this->queryCompiler = $queryCompiler;
59 1
        $this->parameterManager = $parameterManager;
60 1
        $this->queryFactory = $queryFactory;
61 1
    }
62
63
    /**
64
     * @return BuilderInterface
65
     */
66
    public function getQueryBuilder()
67
    {
68
        return $this;
69
    }
70
71
    /**
72
     * @return TableFactoryInterface
73
     */
74
    public function getTableFactory()
75
    {
76
        return $this->tableFactory;
77
    }
78
79
    /**
80
     * @return QueryCompilerInterface
81
     */
82
    public function getQueryCompiler()
83
    {
84
        return $this->queryCompiler;
85
    }
86
87
    /**
88
     * @return ParameterManagerInterface
89
     */
90 1
    public function getParameterManager()
91
    {
92 1
        return $this->parameterManager;
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98
    public function buildSQL()
99
    {
100
        return $this->getQueryCompiler()->compile($this->getQueryBuilder());
101
    }
102
103
    /**
104
     * @inheritdoc
105
     */
106
    public function objectToString($object)
107
    {
108
        return $this->getParameterManager()->createReference($object);
109
    }
110
111
    /**
112
     * @inheritdoc
113
     */
114
    public function setParameter($name, $value)
115
    {
116
        $parameter = $this->getParameterManager()->createOrGetParameter($name);
117
        $parameter->setValue($value);
118
119
        return $this;
120
    }
121
122
    /**
123
     * @param mixed $connectionHint
124
     *
125
     * @return Query
126
     */
127
    public function buildQuery($connectionHint = null)
128
    {
129
        return $this->queryFactory->buildQuery($this->buildSQL(), $this->getParameterManager(), $connectionHint);
130
    }
131
}