Re: attempting to work out conversion/compression API
| From: | Steph Fox | Date: | Thu, 10 Apr 2008 12:46:02 +0000 |
| Subject: | Re: attempting to work out conversion/compression API | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-5362@lists.php.net to get a copy of this message | ||
Hi Greg,
To satisfy these three requirements, I'd like to use these methods: void PharFileInfo->compress(int $compression) // first 4 throw exceptions on failure like other Phar methods void PharFileInfo->decompress() void Phar->compressFiles(int $compression) void Phar->decompressFiles()So far so good...
Phar|PharData Phar->convert(int $archivetype[, int $compression = Phar::NONE][, bool $executable = true][, string $file_extension])
$archivetype could be any of Phar::PHAR, Phar::TAR or Phar::ZIP.I don't like this, see below.
$compression could be any of Phar::NONE, Phar::GZ, or Phar::BZ2Why Phar::NONE rather than NULL?
$executable is used to determine whether a Phar or PharData object is returned. If true, $archivetype must be Phar::TAR or Phar::ZIP $file_extension can be set to override the automatic renaming (format/compression-dependent)I think the main problem with this approach is that there are four arguments from inception, three of which are likely to be used most of the time. Personally I have problems remembering more than two parameters :) especially when there are extension-specific constants involved. The advantage of having separate methods for convertToTar()|convertToPhar()|convertToZip() is that it removes at least one of those arguments, leaving only $compression, $executable and $file_extension to worry about in the first two methods and only $executable and $file_extension in convertToZip(). Given that most people are unlikely to use $file_extension anyway, I think that would make it much easier to both remember and read. So I'd rather have: $tar = $phar->convertToTar(Phar::GZ, false); rather than: $tar = $phar->convert(Phar::TAR, Phar::GZ, false); and save the all-singing all-dancing convert() for the internal method.
convert returns a new object either of Phar or PharData based on the $executable parameter.This part strikes me as a good idea. It takes the guesswork out of it. Presumably if the $executable parameter is skipped the returned object will be of the same type as the original? - Steph