-
-
Notifications
You must be signed in to change notification settings - Fork 762
/
Copy pathBackupJobFactory.php
39 lines (34 loc) · 1.42 KB
/
BackupJobFactory.php
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
<?php
namespace Spatie\Backup\Tasks\Backup;
use Illuminate\Support\Collection;
use Spatie\Backup\BackupDestination\BackupDestinationFactory;
use Spatie\Backup\Config\Config;
use Spatie\Backup\Config\SourceFilesConfig;
use Spatie\DbDumper\DbDumper;
class BackupJobFactory
{
public static function createFromConfig(Config $config): BackupJob
{
return (new BackupJob($config))
->setFileSelection(static::createFileSelection($config->backup->source->files))
->setDbDumpers(static::createDbDumpers($config->backup->source->databases))
->setBackupDestinations(BackupDestinationFactory::createFromArray($config));
}
protected static function createFileSelection(SourceFilesConfig $sourceFiles): FileSelection
{
return FileSelection::create($sourceFiles->include)
->excludeFilesFrom($sourceFiles->exclude)
->shouldFollowLinks($sourceFiles->followLinks)
->shouldIgnoreUnreadableDirs($sourceFiles->ignoreUnreadableDirectories);
}
/**
* @param array<int, string> $dbConnectionNames
* @return Collection<string, DbDumper>
*/
protected static function createDbDumpers(array $dbConnectionNames): Collection
{
return collect($dbConnectionNames)->mapWithKeys(
fn (string $dbConnectionName): array => [$dbConnectionName => DbDumperFactory::createFromConnection($dbConnectionName)]
);
}
}