cvs: pear /File_Archive Archive.php

From: Date: Mon, 21 Feb 2005 17:23:30 +0000
Subject: cvs: pear /File_Archive Archive.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-29621@lists.php.net to get a copy of this message
vincentlascaux Mon Feb 21 12:23:30 2005 EDT Modified files: /pear/File_Archive Archive.php Log: + No longer need to specify the type of the archive in File_Archive::toArchive (by default, it is determined thanks to the extension in the filename) http://cvs.php.net/diff.php/pear/File_Archive/Archive.php?r1=1.13&r2=1.14&ty=u Index: pear/File_Archive/Archive.php diff -u pear/File_Archive/Archive.php:1.13 pear/File_Archive/Archive.php:1.14 --- pear/File_Archive/Archive.php:1.13 Mon Feb 21 07:32:29 2005 +++ pear/File_Archive/Archive.php Mon Feb 21 12:23:30 2005 @@ -26,7 +26,7 @@ * @author Vincent Lascaux <vincentlascaux@php.net> * @copyright 1997-2005 The PHP Group * @license http://www.gnu.org/copyleft/lesser.html LGPL - * @version CVS: $Id: Archive.php,v 1.13 2005/02/21 12:32:29 vincentlascaux Exp $ + * @version CVS: $Id: Archive.php,v 1.14 2005/02/21 17:23:30 vincentlascaux Exp $ * @link http://pear.php.net/package/File_Archive */ @@ -476,13 +476,26 @@ return new File_Archive_Writer_Output($sendHeaders); } /** - * @param $type can be one of Tar, Gzip, Tgz, Zip - * The case of this parameter is not important - */ - function toArchive($type, $filename, &$innerWriter, $stat = array(), $autoClose = true) - { - $realType = ucfirst($type); - switch($realType) + * @param string $filename name of the archive file + * @param File_Archive_Writer $innerWriter writer where the archive will be written + * @param string $type can be one of Tar, Gz, Gzip, Tgz, Zip (default is the extension of $filename) + * The case of this parameter is not important + * @param array $stat Statistics of the archive (see stat function) + * @param bool $autoClose If set to true, $innerWriter will be closed when the returned archive is close + * Default value is true. + */ + function toArchive($filename, &$innerWriter, $type=null, $stat = array(), $autoClose = true) + { + if($type == null) { + $dotPos = strrpos($filename, '.'); + if($dotPos !== false) { + $type = substr($filename, $dotPos+1); + } else { + return PEAR::raiseError("Unknown archive type for $filename (you should specify a third argument)"); + } + } + $type = ucfirst($type); + switch($type) { case "Tgz": require_once "File/Archive/Writer/Tar.php"; @@ -490,11 +503,15 @@ return new File_Archive_Writer_Tar("$filename.tar", new File_Archive_Writer_Gzip($filename, $innerWriter, $stat), $stat, $autoClose); - - default: - require_once "File/Archive/Writer/$realType.php"; - $class = "File_Archive_Writer_$realType"; + case "Tar": + case "Zip": + case "Gz": + case "Gzip": + require_once "File/Archive/Writer/$type.php"; + $class = "File_Archive_Writer_$type"; return new $class($filename, $innerWriter, $stat, $autoClose); + default: + return PEAR::raiseError("Extension $type unknown"); } } }

« previous php.pear.cvs (#29621) next »