1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Licensed to CRATE Technology GmbH("Crate") under one or more contributor |
4
|
|
|
* license agreements. See the NOTICE file distributed with this work for |
5
|
|
|
* additional information regarding copyright ownership. Crate licenses |
6
|
|
|
* this file to you under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. You may |
8
|
|
|
* obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
14
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
15
|
|
|
* License for the specific language governing permissions and limitations |
16
|
|
|
* under the License. |
17
|
|
|
* |
18
|
|
|
* However, if you have executed another commercial license agreement |
19
|
|
|
* with Crate these terms will supersede the license and you may use the |
20
|
|
|
* software solely pursuant to the terms of the relevant commercial agreement. |
21
|
|
|
*/ |
22
|
|
|
namespace Crate\DBAL\Driver\PDOCrate; |
23
|
|
|
|
24
|
|
|
use Crate\DBAL\Platforms\CratePlatform1; |
25
|
|
|
use Crate\DBAL\Platforms\CratePlatform; |
26
|
|
|
use Crate\DBAL\Platforms\CratePlatform4; |
27
|
|
|
use Crate\DBAL\Schema\CrateSchemaManager; |
28
|
|
|
use Doctrine\DBAL\Connection; |
29
|
|
|
use Doctrine\DBAL\VersionAwarePlatformDriver; |
30
|
|
|
|
31
|
|
|
class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver |
32
|
|
|
{ |
33
|
|
|
const VERSION = '4.0.2'; |
34
|
|
|
const NAME = 'crate'; |
35
|
|
|
|
36
|
|
|
private const VERSION_057 = '0.57.0'; |
37
|
|
|
private const VERSION_4 = '4.0.0'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritDoc} |
41
|
|
|
* @return PDOConnection The database connection. |
42
|
|
|
*/ |
43
|
12 |
|
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) |
44
|
|
|
{ |
45
|
12 |
|
return new PDOConnection($this->constructPdoDsn($params), $username, $password, $driverOptions); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Constructs the Crate PDO DSN. |
50
|
|
|
* |
51
|
|
|
* @return string The DSN. |
52
|
|
|
*/ |
53
|
12 |
|
private function constructPdoDsn(array $params) |
54
|
|
|
{ |
55
|
12 |
|
$dsn = self::NAME . ':'; |
56
|
12 |
|
if (isset($params['host']) && $params['host'] != '') { |
57
|
12 |
|
$dsn .= $params['host']; |
58
|
|
|
} else { |
59
|
|
|
$dsn .= 'localhost'; |
60
|
|
|
} |
61
|
12 |
|
$dsn .= ':' . (isset($params['port']) ? $params['port'] : '4200'); |
62
|
|
|
|
63
|
12 |
|
return $dsn; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritDoc} |
68
|
|
|
*/ |
69
|
|
|
public function getDatabasePlatform() |
70
|
|
|
{ |
71
|
|
|
return new CratePlatform(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritDoc} |
76
|
|
|
*/ |
77
|
4 |
|
public function getSchemaManager(Connection $conn) |
78
|
|
|
{ |
79
|
4 |
|
return new CrateSchemaManager($conn); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* {@inheritDoc} |
84
|
|
|
*/ |
85
|
|
|
public function getName() |
86
|
|
|
{ |
87
|
|
|
return self::NAME; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritDoc} |
92
|
|
|
*/ |
93
|
10 |
|
public function getDatabase(Connection $conn) |
94
|
|
|
{ |
95
|
10 |
|
return null; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritDoc} |
100
|
|
|
*/ |
101
|
238 |
|
public function createDatabasePlatformForVersion($version) |
102
|
|
|
{ |
103
|
238 |
|
if (version_compare($version, self::VERSION_057, "<")) { |
104
|
2 |
|
return new CratePlatform(); |
105
|
236 |
|
} elseif (version_compare($version, self::VERSION_4, "<")) { |
106
|
2 |
|
return new CratePlatform1(); |
107
|
|
|
} else { |
108
|
234 |
|
return new CratePlatform4(); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: