Skip to content

Commit 1a3a67b

Browse files
committed
Implemented PdoDriverAwareInterface for Pdo\Statement
Cleanup for satellite packages
1 parent 78c83e6 commit 1a3a67b

File tree

3 files changed

+82
-67
lines changed

3 files changed

+82
-67
lines changed

src/Adapter/Driver/Pdo/Statement.php

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Laminas\Db\Adapter\Driver\Pdo;
44

5+
use Laminas\Db\Adapter\Driver\PdoDriverAwareInterface;
56
use Laminas\Db\Adapter\Driver\PdoDriverInterface;
6-
use Laminas\Db\Adapter\Driver\PdoStatementInterface;
77
use Laminas\Db\Adapter\Driver\ResultInterface;
88
use Laminas\Db\Adapter\Driver\StatementInterface;
99
use Laminas\Db\Adapter\Exception;
@@ -19,15 +19,15 @@
1919
use function is_bool;
2020
use function is_int;
2121

22-
class Statement implements StatementInterface, PdoStatementInterface, Profiler\ProfilerAwareInterface
22+
class Statement implements StatementInterface, PdoDriverAwareInterface, Profiler\ProfilerAwareInterface
2323
{
2424
/** @var PDO */
2525
protected $pdo;
2626

2727
/** @var Profiler\ProfilerInterface */
2828
protected $profiler;
2929

30-
/** @var \Laminas\Db\Adapter\Driver\PdoDriverInterface */
30+
/** @var PdoDriverInterface */
3131
protected $driver;
3232

3333
/** @var string */
@@ -57,22 +57,24 @@ class Statement implements StatementInterface, PdoStatementInterface, Profiler\P
5757
public function setDriver(PdoDriverInterface $driver): static
5858
{
5959
$this->driver = $driver;
60+
6061
return $this;
6162
}
6263

64+
public function getProfiler(): ?Profiler\ProfilerInterface
65+
{
66+
return $this->profiler;
67+
}
68+
6369
/**
6470
* @return $this Provides a fluent interface
6571
*/
6672
#[Override]
6773
public function setProfiler(Profiler\ProfilerInterface $profiler): static
6874
{
6975
$this->profiler = $profiler;
70-
return $this;
71-
}
7276

73-
public function getProfiler(): ?Profiler\ProfilerInterface
74-
{
75-
return $this->profiler;
77+
return $this;
7678
}
7779

7880
/**
@@ -83,9 +85,20 @@ public function getProfiler(): ?Profiler\ProfilerInterface
8385
public function initialize(PDO $connectionResource)
8486
{
8587
$this->pdo = $connectionResource;
88+
8689
return $this;
8790
}
8891

92+
/**
93+
* Get resource
94+
*
95+
* @return mixed
96+
*/
97+
public function getResource()
98+
{
99+
return $this->resource;
100+
}
101+
89102
/**
90103
* Set resource
91104
*
@@ -94,17 +107,61 @@ public function initialize(PDO $connectionResource)
94107
public function setResource(PDOStatement $pdoStatement)
95108
{
96109
$this->resource = $pdoStatement;
110+
97111
return $this;
98112
}
99113

100114
/**
101-
* Get resource
115+
* Perform a deep clone
102116
*
103-
* @return mixed
117+
* @return void
104118
*/
105-
public function getResource()
119+
public function __clone()
106120
{
107-
return $this->resource;
121+
$this->isPrepared = false;
122+
$this->parametersBound = false;
123+
$this->resource = null;
124+
if ($this->parameterContainer) {
125+
$this->parameterContainer = clone $this->parameterContainer;
126+
}
127+
}
128+
129+
/**
130+
* Bind parameters from container
131+
*/
132+
protected function bindParametersFromContainer()
133+
{
134+
if ($this->parametersBound) {
135+
return;
136+
}
137+
138+
$parameters = $this->parameterContainer->getNamedArray();
139+
foreach ($parameters as $name => &$value) {
140+
if (is_bool($value)) {
141+
$type = PDO::PARAM_BOOL;
142+
} elseif (is_int($value)) {
143+
$type = PDO::PARAM_INT;
144+
} else {
145+
$type = PDO::PARAM_STR;
146+
}
147+
if ($this->parameterContainer->offsetHasErrata($name)) {
148+
switch ($this->parameterContainer->offsetGetErrata($name)) {
149+
case ParameterContainer::TYPE_INTEGER:
150+
$type = PDO::PARAM_INT;
151+
break;
152+
case ParameterContainer::TYPE_NULL:
153+
$type = PDO::PARAM_NULL;
154+
break;
155+
case ParameterContainer::TYPE_LOB:
156+
$type = PDO::PARAM_LOB;
157+
break;
158+
}
159+
}
160+
161+
// parameter is named or positional, value is reference
162+
$parameter = is_int($name) ? $name + 1 : $this->driver->formatParameterName($name);
163+
$this->resource->bindParam($parameter, $value, $type);
164+
}
108165
}
109166

110167
/**
@@ -116,6 +173,7 @@ public function getResource()
116173
public function setSql($sql): static
117174
{
118175
$this->sql = $sql;
176+
119177
return $this;
120178
}
121179

@@ -135,6 +193,7 @@ public function getSql(): ?string
135193
public function setParameterContainer(ParameterContainer $parameterContainer)
136194
{
137195
$this->parameterContainer = $parameterContainer;
196+
138197
return $this;
139198
}
140199

@@ -232,57 +291,4 @@ public function execute(null|array|ParameterContainer $parameters = null): ?Resu
232291

233292
return $this->driver->createResult($this->resource, $this);
234293
}
235-
236-
/**
237-
* Bind parameters from container
238-
*/
239-
protected function bindParametersFromContainer()
240-
{
241-
if ($this->parametersBound) {
242-
return;
243-
}
244-
245-
$parameters = $this->parameterContainer->getNamedArray();
246-
foreach ($parameters as $name => &$value) {
247-
if (is_bool($value)) {
248-
$type = \PDO::PARAM_BOOL;
249-
} elseif (is_int($value)) {
250-
$type = \PDO::PARAM_INT;
251-
} else {
252-
$type = \PDO::PARAM_STR;
253-
}
254-
if ($this->parameterContainer->offsetHasErrata($name)) {
255-
switch ($this->parameterContainer->offsetGetErrata($name)) {
256-
case ParameterContainer::TYPE_INTEGER:
257-
$type = \PDO::PARAM_INT;
258-
break;
259-
case ParameterContainer::TYPE_NULL:
260-
$type = \PDO::PARAM_NULL;
261-
break;
262-
case ParameterContainer::TYPE_LOB:
263-
$type = \PDO::PARAM_LOB;
264-
break;
265-
}
266-
}
267-
268-
// parameter is named or positional, value is reference
269-
$parameter = is_int($name) ? $name + 1 : $this->driver->formatParameterName($name);
270-
$this->resource->bindParam($parameter, $value, $type);
271-
}
272-
}
273-
274-
/**
275-
* Perform a deep clone
276-
*
277-
* @return void
278-
*/
279-
public function __clone()
280-
{
281-
$this->isPrepared = false;
282-
$this->parametersBound = false;
283-
$this->resource = null;
284-
if ($this->parameterContainer) {
285-
$this->parameterContainer = clone $this->parameterContainer;
286-
}
287-
}
288294
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Laminas\Db\Adapter\Driver;
6+
7+
interface PdoDriverAwareInterface
8+
{
9+
/** Provides a fluent interface - implementation must return $this */
10+
public function setDriver(PdoDriverInterface $driver): static;
11+
}

src/Adapter/Driver/StatementInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
interface StatementInterface extends StatementContainerInterface
99
{
10-
public function setDriver(DriverInterface $driver): static;
11-
1210
/**
1311
* Get resource
1412
*

0 commit comments

Comments
 (0)