|
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\Platforms\AbstractPlatform; |
|
10
|
|
|
use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion; |
|
11
|
|
|
use Doctrine\DBAL\Platforms\SQLServer2012Platform; |
|
12
|
|
|
use Doctrine\DBAL\Platforms\SQLServerPlatform; |
|
13
|
|
|
use Doctrine\DBAL\Schema\AbstractSchemaManager; |
|
14
|
|
|
use Doctrine\DBAL\Schema\SQLServerSchemaManager; |
|
15
|
|
|
use Doctrine\DBAL\VersionAwarePlatformDriver; |
|
16
|
|
|
use function preg_match; |
|
17
|
|
|
use function version_compare; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Microsoft SQL Server based drivers. |
|
21
|
|
|
*/ |
|
22
|
|
|
abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDriver |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
274 |
|
public function createDatabasePlatformForVersion(string $version) : AbstractPlatform |
|
28
|
|
|
{ |
|
29
|
274 |
|
if (! preg_match( |
|
30
|
2 |
|
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+)(?:\.(?P<build>\d+))?)?)?/', |
|
31
|
274 |
|
$version, |
|
32
|
274 |
|
$versionParts |
|
33
|
|
|
)) { |
|
34
|
248 |
|
throw InvalidPlatformVersion::new( |
|
35
|
248 |
|
$version, |
|
36
|
248 |
|
'<major_version>.<minor_version>.<patch_version>.<build_version>' |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
273 |
|
$majorVersion = $versionParts['major']; |
|
41
|
273 |
|
$minorVersion = $versionParts['minor'] ?? 0; |
|
42
|
273 |
|
$patchVersion = $versionParts['patch'] ?? 0; |
|
43
|
273 |
|
$buildVersion = $versionParts['build'] ?? 0; |
|
44
|
273 |
|
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion; |
|
45
|
|
|
|
|
46
|
|
|
switch (true) { |
|
47
|
273 |
|
case version_compare($version, '11.00.2100', '>='): |
|
48
|
273 |
|
return new SQLServer2012Platform(); |
|
49
|
|
|
default: |
|
50
|
273 |
|
return new SQLServerPlatform(); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
223 |
|
public function getDatabasePlatform() : AbstractPlatform |
|
58
|
|
|
{ |
|
59
|
223 |
|
return new SQLServerPlatform(); |
|
60
|
|
|
} |
|
61
|
223 |
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getSchemaManager(Connection $conn) : AbstractSchemaManager |
|
66
|
|
|
{ |
|
67
|
198 |
|
return new SQLServerSchemaManager($conn); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: