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
|
451 |
|
public function convertException(string $message, DriverExceptionInterface $exception) : DriverException |
24
|
|
|
{ |
25
|
451 |
|
switch ($exception->getCode()) { |
26
|
451 |
|
case 1: |
27
|
405 |
|
case 2299: |
28
|
383 |
|
case 38911: |
29
|
90 |
|
return new Exception\UniqueConstraintViolationException($message, $exception); |
30
|
|
|
|
31
|
361 |
|
case 904: |
32
|
23 |
|
return new Exception\InvalidFieldNameException($message, $exception); |
33
|
|
|
|
34
|
338 |
|
case 918: |
35
|
315 |
|
case 960: |
36
|
45 |
|
return new Exception\NonUniqueFieldNameException($message, $exception); |
37
|
|
|
|
38
|
293 |
|
case 923: |
39
|
23 |
|
return new Exception\SyntaxErrorException($message, $exception); |
40
|
|
|
|
41
|
270 |
|
case 942: |
42
|
76 |
|
return new Exception\TableNotFoundException($message, $exception); |
43
|
|
|
|
44
|
247 |
|
case 955: |
45
|
24 |
|
return new Exception\TableExistsException($message, $exception); |
46
|
|
|
|
47
|
223 |
|
case 1017: |
48
|
199 |
|
case 12545: |
49
|
47 |
|
return new Exception\ConnectionException($message, $exception); |
50
|
|
|
|
51
|
176 |
|
case 1400: |
52
|
23 |
|
return new Exception\NotNullConstraintViolationException($message, $exception); |
53
|
|
|
|
54
|
153 |
|
case 2266: |
55
|
153 |
|
case 2291: |
56
|
153 |
|
case 2292: |
57
|
26 |
|
return new Exception\ForeignKeyConstraintViolationException($message, $exception); |
58
|
|
|
} |
59
|
|
|
|
60
|
131 |
|
return new DriverException($message, $exception); |
61
|
|
|
} |
62
|
|
|
|
63
|
42 |
|
public function getDatabasePlatform() : AbstractPlatform |
64
|
|
|
{ |
65
|
42 |
|
return new OraclePlatform(); |
66
|
|
|
} |
67
|
|
|
|
68
|
32 |
|
public function getSchemaManager(Connection $conn) : AbstractSchemaManager |
69
|
|
|
{ |
70
|
32 |
|
return new OracleSchemaManager($conn); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns an appropriate Easy Connect String for the given parameters. |
75
|
|
|
* |
76
|
|
|
* @param mixed[] $params The connection parameters to return the Easy Connect String for. |
77
|
|
|
*/ |
78
|
29 |
|
protected function getEasyConnectString(array $params) : string |
79
|
|
|
{ |
80
|
29 |
|
return (string) EasyConnectString::fromConnectionParameters($params); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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: