1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Phalcon Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Phalcon Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* Implementation of this file has been influenced by AtlasPHP |
12
|
|
|
* |
13
|
|
|
* @link https://github.com/atlasphp/Atlas.Pdo |
14
|
|
|
* @license https://github.com/atlasphp/Atlas.Pdo/blob/1.x/LICENSE.md |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
declare(strict_types=1); |
18
|
|
|
|
19
|
|
|
namespace Phalcon\DataMapper\Pdo\Connection; |
20
|
|
|
|
21
|
|
|
use PDO; |
22
|
|
|
use Phalcon\DataMapper\Pdo\Exception\CannotDisconnect; |
23
|
|
|
use Phalcon\DataMapper\Pdo\Profiler\Profiler; |
24
|
|
|
use Phalcon\DataMapper\Pdo\Profiler\ProfilerInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Decorates an existing PDO instance with the extended methods. |
28
|
|
|
*/ |
29
|
|
|
class Decorated extends AbstractConnection |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* |
33
|
|
|
* Constructor. |
34
|
|
|
* |
35
|
|
|
* This overrides the parent so that it can take an existing PDO instance |
36
|
|
|
* and decorate it with the extended methods. |
37
|
|
|
* |
38
|
|
|
* @param PDO $pdo |
39
|
|
|
* @param ProfilerInterface|null $profiler |
40
|
|
|
* |
41
|
|
|
*/ |
42
|
2 |
|
public function __construct(PDO $pdo, ProfilerInterface $profiler = null) |
43
|
|
|
{ |
44
|
2 |
|
$this->pdo = $pdo; |
45
|
|
|
|
46
|
2 |
|
if ($profiler === null) { |
47
|
2 |
|
$profiler = new Profiler(); |
48
|
|
|
} |
49
|
2 |
|
$this->setProfiler($profiler); |
50
|
2 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Connects to the database. |
54
|
|
|
*/ |
55
|
1 |
|
public function connect(): void |
56
|
|
|
{ |
57
|
|
|
// already connected |
58
|
1 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Disconnects from the database; disallowed with decorated PDO connections. |
62
|
|
|
* |
63
|
|
|
* @throws CannotDisconnect |
64
|
|
|
*/ |
65
|
1 |
|
public function disconnect(): void |
66
|
|
|
{ |
67
|
1 |
|
$message = "Cannot disconnect a Decorated connection instance"; |
68
|
1 |
|
throw new CannotDisconnect($message); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|