forked from liip/LiipTestFixturesBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractDbalDatabaseTool.php
More file actions
executable file
·53 lines (43 loc) · 1.63 KB
/
AbstractDbalDatabaseTool.php
File metadata and controls
executable file
·53 lines (43 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
/*
* This file is part of the Liip/TestFixturesBundle
*
* (c) Lukas Kahwe Smith <smith@pooteeweet.org>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Liip\TestFixturesBundle\Services\DatabaseTools;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\ORM\EntityManagerInterface;
abstract class AbstractDbalDatabaseTool extends AbstractDatabaseTool
{
protected ?Connection $connection;
public function setObjectManagerName(?string $omName = null): void
{
parent::setObjectManagerName($omName);
if ($this->om instanceof EntityManagerInterface) {
$this->connection = $this->om->getConnection();
} else {
$this->connection = $this->registry->getConnection($omName);
}
}
protected function getPlatformName(): string
{
$platform = $this->connection->getDatabasePlatform();
// AbstractMySQLPlatform was introduced in DBAL 3.3, keep the MySQLPlatform checks for compatibility with older versions
if ($platform instanceof AbstractMySQLPlatform || $platform instanceof MySQLPlatform) {
return 'mysql';
} elseif ($platform instanceof SQLitePlatform) {
return 'sqlite';
} elseif ($platform instanceof PostgreSQLPlatform) {
return 'pgsql';
}
return (new \ReflectionClass($platform))->getShortName();
}
}