-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathBackupperFactory.php
More file actions
59 lines (50 loc) · 1.94 KB
/
BackupperFactory.php
File metadata and controls
59 lines (50 loc) · 1.94 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
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace MakinaCorpus\DbToolsBundle\Backupper;
use MakinaCorpus\DbToolsBundle\Configuration\ConfigurationRegistry;
use MakinaCorpus\DbToolsBundle\Database\DatabaseSessionRegistry;
use MakinaCorpus\DbToolsBundle\Error\NotImplementedException;
use MakinaCorpus\QueryBuilder\Vendor;
use Psr\Log\LoggerInterface;
class BackupperFactory
{
public function __construct(
private DatabaseSessionRegistry $registry,
private ConfigurationRegistry $configRegistry = new ConfigurationRegistry(),
private ?LoggerInterface $logger = null,
) {}
/**
* Get a Backupper for the given connection.
*
* @throws \InvalidArgumentException
*/
public function create(?string $connectionName = null): AbstractBackupper
{
$connectionName ??= $this->registry->getDefaultConnectionName();
$dsn = $this->registry->getConnectionDsn($connectionName);
$vendorName = $dsn->getVendor();
$backupper = match ($vendorName) {
Vendor::MARIADB => MariadbBackupper::class,
Vendor::MYSQL => MysqlBackupper::class,
Vendor::POSTGRESQL => PgsqlBackupper::class,
Vendor::SQLITE => SqliteBackupper::class,
default => throw new NotImplementedException(\sprintf(
"Backup is not implemented or configured for platform '%s' while using connection '%s'",
$vendorName,
$connectionName
)),
};
$backupper = new $backupper(
$this->registry->getDatabaseSession($connectionName),
$dsn,
$this->configRegistry->getConnectionConfig($connectionName),
);
if (isset($this->excludedTables[$connectionName])) {
$backupper->setExcludedTables($this->excludedTables[$connectionName]);
}
if ($this->logger) {
$backupper->setLogger($this->logger);
}
return $backupper;
}
}