* @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:----sLJOJi6eiTg2E17CJ5uIS/gbmmeJ1fmVWYC5PugvtaBZc8YnTfvcURyNd1YfCI5wqaWAbpLDrsH3Oj3I94Th+oiuhjrorXp0e0OGWTN5lvWdJGJjGqJ2108OHtvso0iauBX+6VECqJ1ss8rqOKbhJPKVRweUrCGBDA73KMGJYmCrhM7QylHN3M+BEIj9SCYGjmFaSpDkvSKk5xigDai0lgx/dS0jdM8cmLmdNN3LdImbe5eD4Rt8vVyXFoGCg0X+0oxlfEtPzF30y0JsNNNYtq8alnKLeoeaWe61BLYcN0lsu84SBKr+9IM1bXxcrCAlyVHuDxwUgs1QOhPmutqcnR7cMYnzPx7SsN+1xmXFle6JAYC/EyM3wh8TRbfb8J+aeL/5qukyD8VKXvzAKWC//Hrs25kpKf9uvuOa7wm0B5D7AQNgIyvhjhCwAjg+BnM+ehS98UBek3YFPlzaCZfhA/nxVK3z/MNTJ7E+FHSf/HN6Q3DiFmAr1vqBk8Q0DPpalWplnr2LWvZc2/B8gipzstjb5hS1kCFSibRMEevAkv1oxo3eiCA18YGeTCOi396G+O87XX7ZMPqIwmu7xJlHA66FpTXQrM9J1WAI3p+edxpES8+WZdkMWFpJg3qvednA09pp/cZKrYrr6YMs8bejt7Ho0cxFuagCiQDg6fRAl4I=----ATTACHMENT:----NjQ2MjUxNzMxMDAzNzY2NCA5MjY0MzI0MjI3NTIxNzY4IDg1NjIyNjI4MTU1NzUyNDg=