Compression
1 day ago
Database
1 day ago
DirectoryExplorer
1 day ago
AbstractBackgroundBackupRequest.php
1 day ago
AbstractBackupsFinder.php
1 day ago
AbstractExtractor.php
1 day ago
AbstractServiceProvider.php
1 day ago
Archiver.php
1 day ago
BackupAssets.php
1 day ago
BackupContent.php
1 day ago
BackupMetadataEditor.php
1 day ago
BackupMetadataReader.php
1 day ago
BackupSigner.php
1 day ago
BackupsDirectoryResolver.php
1 day ago
BackupsFinder.php
1 day ago
BeforeUpdateBackupRequest.php
1 day ago
BeforeUpdateBackupsService.php
1 day ago
Extractor.php
1 day ago
FileBackupService.php
1 day ago
FileBackupServiceProvider.php
1 day ago
ServiceInterface.php
1 day ago
TmpBackupCleaner.php
1 day ago
UpdateProtectionHealth.php
1 day ago
UpdateProtectionSettings.php
1 day ago
ZlibCompressor.php
1 day ago
ZlibCompressor.php
83 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backup\Service; |
| 4 | |
| 5 | use WPStaging\Backup\Service\Compression\CompressionInterface; |
| 6 | use WPStaging\Core\WPStaging; |
| 7 | use WPStaging\Framework\Facades\Hooks; |
| 8 | use WPStaging\Framework\Job\Dto\JobDataDto; |
| 9 | |
| 10 | class ZlibCompressor |
| 11 | { |
| 12 | |
| 13 | const FILTER_ZLIB_COMPRESSION_ENABLED = 'wpstg.backup.compression.zlib.enabled'; |
| 14 | |
| 15 | |
| 16 | const HOOK_CAN_USE_COMPRESSION = 'wpstg.can_use_compression'; |
| 17 | |
| 18 | |
| 19 | protected $service; |
| 20 | |
| 21 | public function __construct(CompressionInterface $service) |
| 22 | { |
| 23 | $this->service = $service; |
| 24 | } |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | public function supportsCompression(): bool |
| 30 | { |
| 31 | return function_exists('gzcompress') && function_exists('gzuncompress'); |
| 32 | } |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | public function canUseCompression(): bool |
| 39 | { |
| 40 | static $canUseCompression = null; |
| 41 | |
| 42 | if (!is_null($canUseCompression)) { |
| 43 | return $canUseCompression; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | if (WPStaging::isBasic()) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | $canUseCompression = $this->supportsCompression() && Hooks::callInternalHook(self::HOOK_CAN_USE_COMPRESSION, [], false); |
| 52 | |
| 53 | return $canUseCompression; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | public function isCompressionEnabled(): bool |
| 60 | { |
| 61 | |
| 62 | if (Hooks::applyFilters(JobDataDto::FILTER_IS_MULTIPART_BACKUP, false)) { |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | static $isEnabled = null; |
| 67 | |
| 68 | if (is_null($isEnabled)) { |
| 69 | $settings = (object)get_option('wpstg_settings', []); |
| 70 | $isEnabled = $settings->enableCompression ?? false; |
| 71 | } |
| 72 | |
| 73 | $canUseCompression = $this->canUseCompression(); |
| 74 | |
| 75 | return Hooks::applyFilters(self::FILTER_ZLIB_COMPRESSION_ENABLED, $isEnabled && $canUseCompression); |
| 76 | } |
| 77 | |
| 78 | public function getService(): CompressionInterface |
| 79 | { |
| 80 | return $this->service; |
| 81 | } |
| 82 | } |
| 83 |