PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.3.0
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.3.0
4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backup / Service / ZlibCompressor.php
wp-staging / Backup / Service Last commit date
Compression 1 year ago Database 1 year ago AbstractBackupsFinder.php 1 year ago AbstractExtractor.php 10 months ago AbstractServiceProvider.php 1 year ago Archiver.php 11 months ago BackupAssets.php 2 years ago BackupContent.php 1 year ago BackupMetadataEditor.php 1 year ago BackupMetadataReader.php 1 year ago BackupSigner.php 1 year ago BackupsFinder.php 1 year ago Extractor.php 10 months ago FileBackupService.php 11 months ago FileBackupServiceProvider.php 1 year ago ServiceInterface.php 1 year ago ZlibCompressor.php 11 months 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 /** @var string */
13 const FILTER_ZLIB_COMPRESSION_ENABLED = 'wpstg.backup.compression.zlib.enabled';
14
15 /** @var string */
16 const HOOK_CAN_USE_COMPRESSION = 'wpstg.can_use_compression';
17
18 /** @var CompressionInterface */
19 protected $service;
20
21 public function __construct(CompressionInterface $service)
22 {
23 $this->service = $service;
24 }
25
26 /**
27 * @return bool Whether the server supports compression.
28 */
29 public function supportsCompression(): bool
30 {
31 return function_exists('gzcompress') && function_exists('gzuncompress');
32 }
33
34 /**
35 * @see \WPStaging\Backup\BackupServiceProvider::registerClasses For the filter.
36 * @return bool Whether the user can use compression.
37 */
38 public function canUseCompression(): bool
39 {
40 static $canUseCompression = null;
41
42 if (!is_null($canUseCompression)) {
43 return $canUseCompression;
44 }
45
46 // Early bail if it is a basic version.
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 * @return bool True if compression is enabled, false if not.
58 */
59 public function isCompressionEnabled(): bool
60 {
61 // We don't support (database) compression when multipart backup is enabled.
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