/** * @param CompressorInterface $compressor * * @throws \RuntimeException * * @return $this */ public function setCompressor(CompressorInterface $compressor) { if (!$compressor->isSupported()) { throw new \RuntimeException('Unsupported type of compressor: ' . $compressor->getName()); } $this->compressor = $compressor; return $this; }
/** * {@inheritdoc} */ public function decode($data, CompressorInterface $compressor, array $options = []) { $chars = str_split($data, 8); $compressed = ''; foreach ($chars as $char) { $compressed .= chr(bindec($char)); } return $compressor->decompress(base64_decode($compressed)); }
/** * @return bool */ protected function selectCompressor() { if ($this->selectedCompressor) { return true; } if (isset($this->children[$this->options['preferred_choice']])) { $this->selectedCompressor = $this->children[$this->options['preferred_choice']]; if ($this->selectedCompressor->isSupported()) { return true; } } foreach ($this->children as $compressor) { if ($compressor->isSupported()) { $this->selectedCompressor = $compressor; return true; } } return false; }