crate /
crate-dbal
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Licensed to CRATE Technology GmbH("Crate") under one or more contributor |
||
| 5 | * license agreements. See the NOTICE file distributed with this work for |
||
| 6 | * additional information regarding copyright ownership. Crate licenses |
||
| 7 | * this file to you under the Apache License, Version 2.0 (the "License"); |
||
| 8 | * you may not use this file except in compliance with the License. You may |
||
| 9 | * obtain a copy of the License at |
||
| 10 | * |
||
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
| 12 | * |
||
| 13 | * Unless required by applicable law or agreed to in writing, software |
||
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
||
| 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
||
| 16 | * License for the specific language governing permissions and limitations |
||
| 17 | * under the License. |
||
| 18 | * |
||
| 19 | * However, if you have executed another commercial license agreement |
||
| 20 | * with Crate these terms will supersede the license and you may use the |
||
| 21 | * software solely pursuant to the terms of the relevant commercial agreement. |
||
| 22 | */ |
||
| 23 | |||
| 24 | namespace Crate\DBAL\Driver\PDOCrate; |
||
| 25 | |||
| 26 | use Crate\DBAL\Platforms\CratePlatform; |
||
| 27 | use Crate\DBAL\Platforms\CratePlatform1; |
||
| 28 | use Crate\DBAL\Platforms\CratePlatform4; |
||
| 29 | use Crate\DBAL\Schema\CrateSchemaManager; |
||
| 30 | use Doctrine\DBAL\Connection; |
||
| 31 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
||
| 32 | use Doctrine\DBAL\Schema\AbstractSchemaManager; |
||
| 33 | use Doctrine\DBAL\VersionAwarePlatformDriver; |
||
| 34 | use SensitiveParameter; |
||
| 35 | |||
| 36 | class Driver implements VersionAwarePlatformDriver |
||
| 37 | { |
||
| 38 | public const VERSION = '4.0.3'; |
||
| 39 | public const NAME = 'crate'; |
||
| 40 | |||
| 41 | private const VERSION_057 = '0.57.0'; |
||
| 42 | private const VERSION_4 = '4.0.0'; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritDoc} |
||
| 46 | * @return PDOConnection The database connection. |
||
| 47 | */ |
||
| 48 | 16 | public function connect( |
|
| 49 | #[SensitiveParameter] |
||
| 50 | array $params |
||
| 51 | ): PDOConnection { |
||
| 52 | 16 | $username = $params['user'] ?? null; |
|
| 53 | 16 | $password = $params['password'] ?? null; |
|
| 54 | 16 | $driverOptions = $params['driver_options'] ?? []; |
|
| 55 | 16 | return new PDOConnection($this->constructPdoDsn($params), $username, $password, $driverOptions); |
|
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Constructs the Crate PDO DSN. |
||
| 60 | * |
||
| 61 | * @return string The DSN. |
||
| 62 | */ |
||
| 63 | 16 | private function constructPdoDsn(array $params): string |
|
| 64 | { |
||
| 65 | 16 | $dsn = self::NAME . ':'; |
|
| 66 | 16 | if (isset($params['host']) && $params['host'] != '') { |
|
| 67 | 16 | $dsn .= $params['host']; |
|
| 68 | } else { |
||
| 69 | $dsn .= 'localhost'; |
||
| 70 | } |
||
| 71 | 16 | $dsn .= ':' . (isset($params['port']) ? $params['port'] : '4200'); |
|
| 72 | |||
| 73 | 16 | return $dsn; |
|
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritDoc} |
||
| 78 | */ |
||
| 79 | 2 | public function getDatabasePlatform(): AbstractPlatform |
|
| 80 | { |
||
| 81 | // FIXME: Chicken egg problem: No connection information here. |
||
| 82 | // Is this meant to "activate" the right platform *after* a server |
||
| 83 | // inquiry at all? Isn't it more likely it is NOT meant to work this way? |
||
| 84 | // Let's investigate how the other vendors are doing it. |
||
| 85 | 2 | $conn = $this->connect(); |
|
|
0 ignored issues
–
show
|
|||
| 86 | $version = $conn->getServerVersion(); |
||
| 87 | $platform = $this->createDatabasePlatformForVersion($version); |
||
| 88 | return $platform; |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * {@inheritDoc} |
||
| 93 | */ |
||
| 94 | public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager |
||
| 95 | { |
||
| 96 | // Added by Doctrine 3. |
||
| 97 | return new CrateSchemaManager($conn, $platform); |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * {@inheritDoc} |
||
| 102 | */ |
||
| 103 | public function getName(): string |
||
| 104 | { |
||
| 105 | return self::NAME; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * {@inheritDoc} |
||
| 110 | */ |
||
| 111 | public function getDatabase(Connection $conn): string|null |
||
| 112 | { |
||
| 113 | return null; |
||
| 114 | } |
||
| 115 | |||
| 116 | /** |
||
| 117 | * {@inheritDoc} |
||
| 118 | */ |
||
| 119 | 240 | public function createDatabasePlatformForVersion($version): AbstractPlatform |
|
| 120 | { |
||
| 121 | 240 | if (version_compare($version, self::VERSION_057, "<")) { |
|
| 122 | 2 | return new CratePlatform(); |
|
| 123 | 238 | } elseif (version_compare($version, self::VERSION_4, "<")) { |
|
| 124 | 2 | return new CratePlatform1(); |
|
| 125 | } else { |
||
| 126 | 236 | return new CratePlatform4(); |
|
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * {@inheritDoc} |
||
| 132 | */ |
||
| 133 | public function getExceptionConverter(): ExceptionConverter |
||
| 134 | { |
||
| 135 | // Added by Doctrine 3. |
||
| 136 | return new ExceptionConverter(); |
||
| 137 | } |
||
| 138 | } |
||
| 139 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.