BackupServiceProvider.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Basic\Backup; |
| 4 | |
| 5 | use WPStaging\Backup\Dto\Job\JobBackupDataDto; |
| 6 | use WPStaging\Backup\Dto\Job\JobRestoreDataDto; |
| 7 | use WPStaging\Backup\Dto\JobDataDto; |
| 8 | use WPStaging\Backup\Job\AbstractJob; |
| 9 | use WPStaging\Backup\Job\JobBackupProvider; |
| 10 | use WPStaging\Backup\Job\JobRestoreProvider; |
| 11 | use WPStaging\Backup\Job\Jobs\JobBackup; |
| 12 | use WPStaging\Backup\Job\Jobs\JobRestore; |
| 13 | use WPStaging\Backup\Service\Database\Exporter\AbstractExporter; |
| 14 | use WPStaging\Backup\Service\Database\Exporter\DDLExporter; |
| 15 | use WPStaging\Backup\Service\Database\Exporter\DDLExporterProvider; |
| 16 | use WPStaging\Backup\Service\Database\Exporter\RowsExporter; |
| 17 | use WPStaging\Backup\Service\Database\Exporter\RowsExporterProvider; |
| 18 | use WPStaging\Backup\Service\Database\Importer\BasicDatabaseSearchReplacer; |
| 19 | use WPStaging\Backup\Service\Database\Importer\DatabaseSearchReplacerInterface; |
| 20 | use WPStaging\Backup\Service\Multipart\MultipartInjection; |
| 21 | use WPStaging\Backup\Service\Multipart\MultipartRestoreInterface; |
| 22 | use WPStaging\Backup\Service\Multipart\MultipartRestorer; |
| 23 | use WPStaging\Backup\Service\Multipart\MultipartSplitInterface; |
| 24 | use WPStaging\Backup\Service\Multipart\MultipartSplitter; |
| 25 | use WPStaging\Backup\Task\Tasks\JobRestore\RestoreDatabaseTask; |
| 26 | use WPStaging\Framework\DI\ServiceProvider; |
| 27 | |
| 28 | /** |
| 29 | * Class BackupServiceProvider |
| 30 | * |
| 31 | * Responsible for injecting classes which are to be used in FREE/BASIC version only |
| 32 | */ |
| 33 | class BackupServiceProvider extends ServiceProvider |
| 34 | { |
| 35 | protected function registerClasses() |
| 36 | { |
| 37 | $this->container->when(JobBackup::class) |
| 38 | ->needs(JobDataDto::class) |
| 39 | ->give(JobBackupDataDto::class); |
| 40 | |
| 41 | $this->container->when(JobRestore::class) |
| 42 | ->needs(JobDataDto::class) |
| 43 | ->give(JobRestoreDataDto::class); |
| 44 | |
| 45 | $container = $this->container; |
| 46 | |
| 47 | $this->container->when(JobBackupProvider::class) |
| 48 | ->needs(AbstractJob::class) |
| 49 | ->give(function () use (&$container) { |
| 50 | return $container->make(JobBackup::class); |
| 51 | }); |
| 52 | |
| 53 | $this->container->when(JobRestoreProvider::class) |
| 54 | ->needs(AbstractJob::class) |
| 55 | ->give(function () use (&$container) { |
| 56 | return $container->make(JobRestore::class); |
| 57 | }); |
| 58 | |
| 59 | $this->container->when(DDLExporterProvider::class) |
| 60 | ->needs(AbstractExporter::class) |
| 61 | ->give(function () use (&$container) { |
| 62 | return $container->make(DDLExporter::class); |
| 63 | }); |
| 64 | |
| 65 | $this->container->when(RowsExporterProvider::class) |
| 66 | ->needs(AbstractExporter::class) |
| 67 | ->give(function () use (&$container) { |
| 68 | return $container->make(RowsExporter::class); |
| 69 | }); |
| 70 | |
| 71 | foreach (MultipartInjection::MULTIPART_CLASSES as $classId) { |
| 72 | $this->container->when($classId) |
| 73 | ->needs(MultipartSplitInterface::class) |
| 74 | ->give(MultipartSplitter::class); |
| 75 | } |
| 76 | |
| 77 | foreach (MultipartInjection::RESTORE_CLASSES as $classId) { |
| 78 | $this->container->when($classId) |
| 79 | ->needs(MultipartRestoreInterface::class) |
| 80 | ->give(MultipartRestorer::class); |
| 81 | } |
| 82 | |
| 83 | $this->container->when(RestoreDatabaseTask::class) |
| 84 | ->needs(DatabaseSearchReplacerInterface::class) |
| 85 | ->give(BasicDatabaseSearchReplacer::class); |
| 86 | } |
| 87 | } |
| 88 |