Completed
Pull Request — master (#3726)
by Sam
23:00
created

Driver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 15
dl 0
loc 43
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A connect() 0 19 3
A constructPdoDsn() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Driver\PDOOracle;
6
7
use Doctrine\DBAL\DBALException;
8
use Doctrine\DBAL\Driver\AbstractOracleDriver;
9
use Doctrine\DBAL\Driver\Connection;
10
use Doctrine\DBAL\Driver\PDOConnection;
11
use Doctrine\DBAL\Driver\PDOException;
12
use PDO;
13
14
/**
15
 * PDO Oracle driver.
16
 *
17
 * WARNING: This driver gives us segfaults in our testsuites on CLOB and other
18
 * stuff. PDO Oracle is not maintained by Oracle or anyone in the PHP community,
19
 * which leads us to the recommendation to use the "oci8" driver to connect
20
 * to Oracle instead.
21
 */
22
class Driver extends AbstractOracleDriver
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function connect(
28
        array $params,
29
        string $username = '',
30
        string $password = '',
31
        array $driverOptions = []
32
    ) : Connection {
33
        if (! empty($params['persistent'])) {
34
            $driverOptions[PDO::ATTR_PERSISTENT] = true;
35
        }
36
37
        try {
38
            return new PDOConnection(
39
                $this->constructPdoDsn($params),
40
                $username,
41
                $password,
42
                $driverOptions
43
            );
44
        } catch (PDOException $e) {
45
            throw DBALException::driverException($this, $e);
46
        }
47
    }
48
49
    /**
50
     * Constructs the Oracle PDO DSN.
51
     *
52
     * @param mixed[] $params
53
     *
54
     * @return string The DSN.
55
     */
56
    private function constructPdoDsn(array $params) : string
57
    {
58
        $dsn = 'oci:dbname=' . $this->getEasyConnectString($params);
59
60
        if (isset($params['charset'])) {
61
            $dsn .= ';charset=' . $params['charset'];
62
        }
63
64
        return $dsn;
65
    }
66
}
67