1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rougin\Windstorm\Doctrine; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
6
|
|
|
use Rougin\Windstorm\QueryInterface; |
7
|
|
|
use Rougin\Windstorm\ResultInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Result |
11
|
|
|
* |
12
|
|
|
* @package Windstorm |
13
|
|
|
* @author Rougin Gutib <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class Result implements ResultInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var \Doctrine\DBAL\Connection |
19
|
|
|
*/ |
20
|
|
|
protected $connection; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \PDOStatement |
24
|
|
|
*/ |
25
|
|
|
protected $result; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initializes the result instance. |
29
|
|
|
* |
30
|
|
|
* @param \Doctrine\DBAL\Connection $connection |
31
|
|
|
*/ |
32
|
24 |
|
public function __construct(Connection $connection) |
33
|
|
|
{ |
34
|
24 |
|
$this->connection = $connection; |
35
|
24 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns a number of affected rows. |
39
|
|
|
* |
40
|
|
|
* @return integer |
41
|
|
|
*/ |
42
|
12 |
|
public function affected() |
43
|
|
|
{ |
44
|
12 |
|
return $this->result->rowCount(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns a result from a query instance. |
49
|
|
|
* |
50
|
|
|
* @param \Rougin\Windstorm\QueryInterface $query |
51
|
|
|
* @return self |
52
|
|
|
*/ |
53
|
24 |
|
public function execute(QueryInterface $query) |
54
|
|
|
{ |
55
|
24 |
|
$bindings = $query->bindings(); |
56
|
|
|
|
57
|
24 |
|
$sql = $query->sql(); |
58
|
|
|
|
59
|
24 |
|
$types = (array) $query->types(); |
60
|
|
|
|
61
|
24 |
|
$connection = $this->connection; |
62
|
|
|
|
63
|
24 |
|
if (strpos($sql, 'SELECT') === false) |
64
|
24 |
|
{ |
65
|
12 |
|
$this->result = $connection->executeUpdate($sql, $bindings, $types); |
|
|
|
|
66
|
12 |
|
} |
67
|
|
|
|
68
|
24 |
|
$this->result = $connection->executeQuery($sql, $bindings, $types); |
69
|
|
|
|
70
|
24 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns the first row from result. |
75
|
|
|
* |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
3 |
|
public function first() |
79
|
|
|
{ |
80
|
3 |
|
return $this->result->fetch(\PDO::FETCH_ASSOC); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Returns all items from the result. |
85
|
|
|
* |
86
|
|
|
* @return mixed |
87
|
|
|
*/ |
88
|
9 |
|
public function items() |
89
|
|
|
{ |
90
|
9 |
|
return $this->result->fetchAll(\PDO::FETCH_ASSOC); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..