Completed
Push — master ( 43fa01...97dfc1 )
by Konstantin
03:15
created

Connection.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Brouzie\Sphinxy;
4
5
use Brouzie\Sphinxy\Connection\ConnectionInterface;
6
use Brouzie\Sphinxy\Logging\LoggerInterface;
7
use Brouzie\Sphinxy\Query\MultiResultSet;
8
use Brouzie\Sphinxy\Query\ResultSet;
9
10
class Connection
11
{
12
    /**
13
     * @var ConnectionInterface
14
     */
15
    private $conn;
16
17
    /**
18
     * @var Escaper
19
     */
20
    private $escaper;
21
22
    /**
23
     * @var LoggerInterface|null
24
     */
25
    private $logger;
26
27
    public function __construct(ConnectionInterface $conn)
28
    {
29
        $this->conn = $conn;
30
    }
31
32
    /**
33
     * @param LoggerInterface|null $logger
34
     */
35
    public function setLogger(LoggerInterface $logger = null)
36
    {
37
        $this->logger = $logger;
38
    }
39
40
    /**
41
     * @return LoggerInterface|null
42
     */
43
    public function getLogger()
44
    {
45
        return $this->logger;
46
    }
47
48 3
    public function executeUpdate($query, array $params = array())
49
    {
50 3
        if (null !== $this->logger) {
51
            $this->logger->startQuery($query);
52
        }
53
54 3
        $result = $this->conn->exec($this->prepareQuery($query, $params));
55
56 3
        if (null !== $this->logger) {
57
            $this->logger->stopQuery();
58
        }
59
60 3
        return $result;
61
    }
62
63 View Code Duplication
    public function executeQuery($query, array $params = array())
64
    {
65
        if (null !== $this->logger) {
66
            $this->logger->startQuery($query, $params);
67
        }
68
69
        $result = $this->conn->query($this->prepareQuery($query, $params));
70
71
        if (null !== $this->logger) {
72
            $this->logger->stopQuery();
73
        }
74
        $meta = $this->conn->query('SHOW META');
75
76
        return new ResultSet($result, $meta);
77
    }
78
79 3 View Code Duplication
    public function executeMultiQuery($query, array $params = array(), array $types = array(), array $resultSetNames = array())
0 ignored issues
show
The parameter $types is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
    {
81 3
        if (null !== $this->logger) {
82
            $this->logger->startQuery($query, $params);
83
        }
84
85 3
        $results = $this->conn->multiQuery($this->prepareQuery($query, $params), $resultSetNames);
86
87 3
        if (null !== $this->logger) {
88
            $this->logger->stopQuery();
89
        }
90 3
        $meta = $this->conn->query('SHOW META');
91
92 3
        return new MultiResultSet($results, $meta);
93
    }
94
95
    public function quote($value)
96
    {
97
        return $this->conn->quote($value);
98
    }
99
100 3
    public function getEscaper()
101
    {
102 3
        if (null === $this->escaper) {
103 3
            $this->escaper = new Escaper($this->conn);
104 3
        }
105
106 3
        return $this->escaper;
107
    }
108
109
    /**
110
     * @return QueryBuilder
111
     */
112
    public function createQueryBuilder()
113
    {
114
        return new QueryBuilder($this);
115
    }
116
117 3
    protected function prepareQuery($query, $params)
118
    {
119 3
        return Util::prepareQuery($query, $params, $this->getEscaper());
120
    }
121
}
122