* @author Nils Adermann * @author Matthieu Moquet */ class PharArchiver implements ArchiverInterface { /** @var array */ protected static $formats = [ 'zip' => \Phar::ZIP, 'tar' => \Phar::TAR, 'tar.gz' => \Phar::TAR, 'tar.bz2' => \Phar::TAR, ]; /** @var array */ protected static $compressFormats = [ 'tar.gz' => \Phar::GZ, 'tar.bz2' => \Phar::BZ2, ]; /** * @inheritDoc */ public function archive( string $sources, string $target, string $format, array $excludes = [], bool $ignoreFilters = false, ): string { $sources = realpath($sources); // Phar would otherwise load the file which we don't want if (file_exists($target)) { unlink($target); } try { $filename = substr($target, 0, strrpos($target, $format) - 1); // Check if compress format if (isset(static::$compressFormats[$format])) { // Current compress format supported base on tar $target = $filename . '.tar'; } $phar = new \PharData( $target, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO, '', static::$formats[$format] ); $files = new ArchivableFilesFinder($sources, $excludes, $ignoreFilters); $filesOnly = new ArchivableFilesFilter($files); $phar->buildFromIterator($filesOnly, $sources); $filesOnly->addEmptyDir($phar, $sources); if (isset(static::$compressFormats[$format])) { // Check can be compressed? if (!$phar->canCompress(static::$compressFormats[$format])) { throw new \RuntimeException(sprintf('Can not compress to %s format', $format)); } // Delete old tar unlink($target); // Compress the new tar $phar->compress(static::$compressFormats[$format]); // Make the correct filename $target = $filename . '.' . $format; } return $target; } catch (\UnexpectedValueException $e) { $message = sprintf( "Could not create archive '%s' from '%s': %s", $target, $sources, $e->getMessage() ); throw new \RuntimeException($message, $e->getCode(), $e); } } /** * @inheritDoc */ public function supports(string $format, ?string $sourceType): bool { return isset(static::$formats[$format]); } } __halt_compiler();----SIGNATURE:----cdQZ8ItLHkf/DAkEDBX2c9NYO7UL5ifxPF4BTq6YRRtl68T7tuO5LQ9dWai1p22aYXCxv7zriRfL8tGNSAR89zhcHqtigbmr+zKaSpyo+DjuTm4glhe5dhATTXPrS/mH+ZA4LeVy8vQTnqHhSW37uQ0Yja+oGpABVInDd5hcuq3gYObBt//1QkqCCEWGAnU+jHQHjG3KspHKzApZgJUZX+PoPE0ftVlXSy374EXlkz0xnRVTcLo7mlyVstl3sBLKtyckg5F5TTBAkkyAQbpnP3NrLYPaBlcMYRqprYaZqJtm9/Ajt2qGKGgImCg8+zjZ5a4GXuRCouCVUsM3+UUeZST4Os4dE7+iExTZLbFqSRzarAI6RwNfjEOjMVkAMVBYoqdqVykfITOh0Z73azDvQgKOAg6UKik4III2jZwN/H/Siu3lqqOzhwBaOiTBeBN6RhMEciBFNMVQHoJgt/LkauCv+mm4FBMrF+mJcOHshzJCBlK5DSkdeIDAn6Bk3SiK2KFS8KbghInnyMtBdmSVeFMc1O/K6flrIqvGTNTjfJma8lFidiE66GpQCA8zYzBRgQitqGfepAj4C/hayGRVkWWoncFQY0mloFk5p5PlG89WtfMIGFMCIHhRh6tPLY/PHjjAXyRfS8waAtHdjHwTZqRd67DXYxVxMdFhDv7g8Wc=----ATTACHMENT:----OTAyNDEyNTgzOTMzMzgwOCA2NDM5MTAzNjU4NTQwODQzIDI3ODgyODIyODM2MjgxMTI=