22 ) { throw new InvalidArgumentException( 'Zstd compression level must be between -1 and 22' ); } $this->config = $config; $this->level = $level; } /** * Whether zstd is supported. * * @return bool */ public function supported(): bool { return function_exists( 'zstd_compress' ); } /** * 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 $this->extension(); } /** * 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 = zstd_compress( $content, $this->level ); if ( $result === false ) { throw new CompressionFailedException( 'Failed to compress content with zstd_compress' ); } return $result; } }