Skip to content

Commit 9cfaa1c

Browse files
committed
try with stubs for CI
1 parent d22b061 commit 9cfaa1c

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Driver\PDO\MySql;
6+
7+
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
8+
use Doctrine\DBAL\Driver\PDO\Connection;
9+
use PDO;
10+
11+
if (class_exists(Driver::class)) {
12+
return;
13+
}
14+
15+
final class Driver extends AbstractMySQLDriver
16+
{
17+
/**
18+
* {@inheritdoc}
19+
*
20+
* @return Connection
21+
*/
22+
public function connect(array $params)
23+
{
24+
$driverOptions = $params['driverOptions'] ?? [];
25+
26+
if (! empty($params['persistent'])) {
27+
$driverOptions[PDO::ATTR_PERSISTENT] = true;
28+
}
29+
30+
return new Connection(
31+
$this->constructPdoDsn($params),
32+
$params['user'] ?? '',
33+
$params['password'] ?? '',
34+
$driverOptions
35+
);
36+
}
37+
38+
/**
39+
* Constructs the MySQL PDO DSN.
40+
*
41+
* @param mixed[] $params
42+
*
43+
* @return string The DSN.
44+
*/
45+
protected function constructPdoDsn(array $params)
46+
{
47+
$dsn = 'mysql:';
48+
if (isset($params['host']) && $params['host'] !== '') {
49+
$dsn .= 'host=' . $params['host'] . ';';
50+
}
51+
52+
if (isset($params['port'])) {
53+
$dsn .= 'port=' . $params['port'] . ';';
54+
}
55+
56+
if (isset($params['dbname'])) {
57+
$dsn .= 'dbname=' . $params['dbname'] . ';';
58+
}
59+
60+
if (isset($params['unix_socket'])) {
61+
$dsn .= 'unix_socket=' . $params['unix_socket'] . ';';
62+
}
63+
64+
if (isset($params['charset'])) {
65+
$dsn .= 'charset=' . $params['charset'] . ';';
66+
}
67+
68+
return $dsn;
69+
}
70+
}

0 commit comments

Comments
 (0)