9 ) { throw new InvalidArgumentException( 'Deflate compression level must be between -1 and 9' ); } $this->config = $config; $this->level = $level; } /** * Whether deflate is supported. * * @return bool */ public function supported(): bool { return function_exists( 'gzcompress' ); } /** * Whether this compressor is enabled. * * @return bool */ public function enabled(): bool { return $this->supported() && $this->config->get( 'page_cache.compression.enabled' ); } /** * The file extension. * * @return string */ public function extension(): string { return self::EXT; } /** * The content encoding header value. * * @return string */ public function encoding(): string { return 'deflate'; } /** * Compress the content. * * @param string $content The content to compress. * * @throws CompressionFailedException When the strategy fails to compress the content. * * @return string */ public function compress( string $content ): string { $result = gzcompress( $content, $this->level ); if ( $result === false ) { throw new CompressionFailedException( 'Failed to compress content with gzcompress' ); } return $result; } }