1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Driver; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Connection; |
|
|
|
|
8
|
|
|
use Doctrine\DBAL\Driver; |
9
|
|
|
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString; |
10
|
|
|
use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface; |
11
|
|
|
use Doctrine\DBAL\Exception; |
12
|
|
|
use Doctrine\DBAL\Exception\DriverException; |
|
|
|
|
13
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
14
|
|
|
use Doctrine\DBAL\Platforms\OraclePlatform; |
15
|
|
|
use Doctrine\DBAL\Schema\AbstractSchemaManager; |
16
|
|
|
use Doctrine\DBAL\Schema\OracleSchemaManager; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers. |
20
|
|
|
*/ |
21
|
|
|
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
237 |
|
public function convertException(string $message, DriverExceptionInterface $exception) : DriverException |
27
|
|
|
{ |
28
|
237 |
|
switch ($exception->getCode()) { |
29
|
162 |
|
case 1: |
30
|
158 |
|
case 2299: |
31
|
157 |
|
case 38911: |
32
|
6 |
|
return new Exception\UniqueConstraintViolationException($message, $exception); |
33
|
|
|
|
34
|
156 |
|
case 904: |
35
|
2 |
|
return new Exception\InvalidFieldNameException($message, $exception); |
36
|
|
|
|
37
|
154 |
|
case 918: |
38
|
152 |
|
case 960: |
39
|
3 |
|
return new Exception\NonUniqueFieldNameException($message, $exception); |
40
|
|
|
|
41
|
151 |
|
case 923: |
42
|
2 |
|
return new Exception\SyntaxErrorException($message, $exception); |
43
|
|
|
|
44
|
149 |
|
case 942: |
45
|
62 |
|
return new Exception\TableNotFoundException($message, $exception); |
46
|
|
|
|
47
|
147 |
|
case 955: |
48
|
24 |
|
return new Exception\TableExistsException($message, $exception); |
49
|
|
|
|
50
|
124 |
|
case 1017: |
51
|
121 |
|
case 12545: |
52
|
80 |
|
return new Exception\ConnectionException($message, $exception); |
53
|
|
|
|
54
|
119 |
|
case 1400: |
55
|
2 |
|
return new Exception\NotNullConstraintViolationException($message, $exception); |
56
|
|
|
|
57
|
117 |
|
case 2266: |
58
|
117 |
|
case 2291: |
59
|
117 |
|
case 2292: |
60
|
5 |
|
return new Exception\ForeignKeyConstraintViolationException($message, $exception); |
61
|
|
|
} |
62
|
|
|
|
63
|
116 |
|
return new DriverException($message, $exception); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
190 |
|
public function getDatabase(Connection $conn) : ?string |
70
|
|
|
{ |
71
|
190 |
|
$params = $conn->getParams(); |
72
|
|
|
|
73
|
190 |
|
return $params['user']; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
70 |
|
public function getDatabasePlatform() : AbstractPlatform |
80
|
|
|
{ |
81
|
70 |
|
return new OraclePlatform(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
36 |
|
public function getSchemaManager(Connection $conn) : AbstractSchemaManager |
88
|
|
|
{ |
89
|
36 |
|
return new OracleSchemaManager($conn); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Returns an appropriate Easy Connect String for the given parameters. |
94
|
|
|
* |
95
|
|
|
* @param mixed[] $params The connection parameters to return the Easy Connect String for. |
96
|
|
|
*/ |
97
|
29 |
|
protected function getEasyConnectString(array $params) : string |
98
|
|
|
{ |
99
|
29 |
|
return (string) EasyConnectString::fromConnectionParameters($params); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: