Completed
Pull Request — develop (#3533)
by
unknown
16:31 queued 01:26
created

Driver::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
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\PDOConnection;
10
use Doctrine\DBAL\Driver\PDOException;
11
use PDO;
12
13
/**
14
 * PDO Oracle driver.
15
 *
16
 * WARNING: This driver gives us segfaults in our testsuites on CLOB and other
17
 * stuff. PDO Oracle is not maintained by Oracle or anyone in the PHP community,
18
 * which leads us to the recommendation to use the "oci8" driver to connect
19
 * to Oracle instead.
20
 */
21
class Driver extends AbstractOracleDriver
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
27
    {
28
        if (! empty($params['persistent'])) {
29
            $driverOptions[PDO::ATTR_PERSISTENT] = true;
30
        }
31
32
        try {
33
            return new PDOConnection(
34
                $this->constructPdoDsn($params),
35
                $username,
36
                $password,
37
                $driverOptions
38
            );
39
        } catch (PDOException $e) {
40
            throw DBALException::driverException($this, $e);
41
        }
42
    }
43
44
    /**
45
     * Constructs the Oracle PDO DSN.
46
     *
47
     * @param mixed[] $params
48
     *
49
     * @return string The DSN.
50
     */
51
    private function constructPdoDsn(array $params)
52
    {
53
        $dsn = 'oci:dbname=' . $this->getEasyConnectString($params);
54
55
        if (isset($params['charset'])) {
56
            $dsn .= ';charset=' . $params['charset'];
57
        }
58
59
        return $dsn;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 27
    public function getName()
66
    {
67 27
        return 'pdo_oracle';
68
    }
69
}
70