BackupServiceProvider.php
102 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Basic\Backup; |
| 4 | |
| 5 | use WPStaging\Backup\Ajax\FileList; |
| 6 | use WPStaging\Backup\Ajax\Listing; |
| 7 | use WPStaging\Backup\Dto\Job\JobBackupDataDto; |
| 8 | use WPStaging\Backup\Dto\Job\JobRestoreDataDto; |
| 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\DatabaseImporter; |
| 14 | use WPStaging\Backup\Service\Compression\CompressionInterface; |
| 15 | use WPStaging\Backup\Service\Compression\NonCompressionService; |
| 16 | use WPStaging\Backup\Service\Database\Exporter\DDLExporter; |
| 17 | use WPStaging\Backup\Service\Database\Exporter\DDLExporterProvider; |
| 18 | use WPStaging\Backup\Service\Database\Exporter\RowsExporter; |
| 19 | use WPStaging\Backup\Service\Database\Exporter\RowsExporterProvider; |
| 20 | use WPStaging\Backup\Service\Database\Importer\BasicDatabaseSearchReplacer; |
| 21 | use WPStaging\Backup\Service\Database\Importer\BasicSubsiteManager; |
| 22 | use WPStaging\Backup\Service\Database\Importer\DatabaseSearchReplacerInterface; |
| 23 | use WPStaging\Backup\Service\Database\Importer\SubsiteManagerInterface; |
| 24 | use WPStaging\Backup\Service\FileBackupService; |
| 25 | use WPStaging\Backup\Service\FileBackupServiceProvider; |
| 26 | use WPStaging\Backup\Service\ServiceInterface; |
| 27 | use WPStaging\Backup\Service\ZlibCompressor; |
| 28 | use WPStaging\Backup\Task\Tasks\JobRestore\RestoreDatabaseTask; |
| 29 | use WPStaging\Framework\Database\Exporter\AbstractExporter; |
| 30 | use WPStaging\Framework\DI\ServiceProvider; |
| 31 | use WPStaging\Framework\Job\AbstractJob; |
| 32 | use WPStaging\Framework\Job\Dto\JobDataDto; |
| 33 | |
| 34 | /** |
| 35 | * Class BackupServiceProvider |
| 36 | * |
| 37 | * Responsible for injecting classes which are to be used in FREE/BASIC version only |
| 38 | */ |
| 39 | class BackupServiceProvider extends ServiceProvider |
| 40 | { |
| 41 | protected function registerClasses() |
| 42 | { |
| 43 | $this->container->when(JobBackup::class) |
| 44 | ->needs(JobDataDto::class) |
| 45 | ->give(JobBackupDataDto::class); |
| 46 | |
| 47 | $this->container->when(JobRestore::class) |
| 48 | ->needs(JobDataDto::class) |
| 49 | ->give(JobRestoreDataDto::class); |
| 50 | |
| 51 | $this->container->when(ZlibCompressor::class) |
| 52 | ->needs(CompressionInterface::class) |
| 53 | ->give(NonCompressionService::class); |
| 54 | |
| 55 | $container = $this->container; |
| 56 | |
| 57 | $this->container->when(JobBackupProvider::class) |
| 58 | ->needs(AbstractJob::class) |
| 59 | ->give(function () use (&$container) { |
| 60 | return $container->make(JobBackup::class); |
| 61 | }); |
| 62 | |
| 63 | $this->container->when(JobRestoreProvider::class) |
| 64 | ->needs(AbstractJob::class) |
| 65 | ->give(function () use (&$container) { |
| 66 | return $container->make(JobRestore::class); |
| 67 | }); |
| 68 | |
| 69 | $this->container->when(FileBackupServiceProvider::class) |
| 70 | ->needs(ServiceInterface::class) |
| 71 | ->give(function () use (&$container) { |
| 72 | return $container->make(FileBackupService::class); |
| 73 | }); |
| 74 | |
| 75 | $this->container->when(DDLExporterProvider::class) |
| 76 | ->needs(AbstractExporter::class) |
| 77 | ->give(function () use (&$container) { |
| 78 | return $container->make(DDLExporter::class); |
| 79 | }); |
| 80 | |
| 81 | $this->container->when(RowsExporterProvider::class) |
| 82 | ->needs(AbstractExporter::class) |
| 83 | ->give(function () use (&$container) { |
| 84 | return $container->make(RowsExporter::class); |
| 85 | }); |
| 86 | |
| 87 | $this->container->when(RestoreDatabaseTask::class) |
| 88 | ->needs(DatabaseSearchReplacerInterface::class) |
| 89 | ->give(BasicDatabaseSearchReplacer::class); |
| 90 | |
| 91 | $this->container->when(DatabaseImporter::class) |
| 92 | ->needs(SubsiteManagerInterface::class) |
| 93 | ->give(BasicSubsiteManager::class); |
| 94 | } |
| 95 | |
| 96 | protected function addHooks() |
| 97 | { |
| 98 | add_action('wp_ajax_wpstg--backups--listing', $this->container->callback(Listing::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 99 | add_action('wp_ajax_wpstg--backups--restore--file-list', $this->container->callback(FileList::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked |
| 100 | } |
| 101 | } |
| 102 |