From: Marcus Boerger Date: Tue, 15 May 2007 15:33:24 +0000 (+0000) Subject: - Add auto compression mode to phar command and use it in Makefile.frag X-Git-Tag: RELEASE_1_2_0~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9deb0ca94fff7ef127e59d0dbff6c0fb122b1152;p=php - Add auto compression mode to phar command and use it in Makefile.frag - Allow parameter types to be based on select type - Allow to use compress command for selected entries --- diff --git a/ext/phar/Makefile.frag b/ext/phar/Makefile.frag index 3acfa94085..dadc024091 100755 --- a/ext/phar/Makefile.frag +++ b/ext/phar/Makefile.frag @@ -3,6 +3,6 @@ $(srcdir)/phar_path_check.c: $(srcdir)/phar_path_check.re $(RE2C) -b -o $(srcdir)/phar_path_check.c $(srcdir)/phar_path_check.re) $(builddir)/phar.phar: $(srcdir)/phar/*.inc $(srcdir)/phar/*.php - php -d phar.readonly=0 $(srcdir)/phar.php pack -f $(builddir)/phar.phar -a pharcommand -c gz -x CVS -s $(srcdir)/phar/phar.php -h sha1 $(srcdir)/phar/ + php -d phar.readonly=0 $(srcdir)/phar.php pack -f $(builddir)/phar.phar -a pharcommand -c auto -x CVS -s $(srcdir)/phar/phar.php -h sha1 $(srcdir)/phar/ @chmod +x $(builddir)/phar.phar diff --git a/ext/phar/phar/clicommand.inc b/ext/phar/phar/clicommand.inc index f2faafccd9..c829f19e1b 100755 --- a/ext/phar/phar/clicommand.inc +++ b/ext/phar/phar/clicommand.inc @@ -289,7 +289,7 @@ abstract class CLICommand $sp2 = $this->cli_get_SP2($l, $inf); $l2 = strlen($sp2); $inf .= $this->cli_wordwrap($sp . $arg . $conf['inf'], $l2, $sp2) . "\n"; - if ($conf['typ'] == 'select') + if (isset($conf['select']) && count($conf['select'])) { $ls = 0; foreach($conf['select'] as $opt => $what) diff --git a/ext/phar/phar/pharcommand.inc b/ext/phar/phar/pharcommand.inc index 9a2c2f86fe..a1a4bbe569 100755 --- a/ext/phar/phar/pharcommand.inc +++ b/ext/phar/phar/pharcommand.inc @@ -30,7 +30,7 @@ class PharCommand extends CLICommand { $phar_args = array( 'a' => array('typ'=>'alias', 'val'=>'newphar', 'inf'=>' Provide an alias name for the phar file.'), - 'c' => array('typ'=>'select', 'val'=>NULL, 'inf'=>' Compression algorithmus.', 'select'=>array('gz'=>'GZip compression','gzip'=>'GZip compression','bzip2'=>'BZip2 compression','bz'=>'BZip2 compression','bz2'=>'BZip2 compression','0'=>'No compression','none'=>'No compression')), + 'c' => array('typ'=>'compalg','val'=>NULL, 'inf'=>' Compression algorithmus.', 'select'=>array('0'=>'No compression','none'=>'No compression','auto'=>'Automatically select compression algorithm')), 'e' => array('typ'=>'entry', 'val'=>NULL, 'inf'=>' Name of entry to work on (must include PHAR internal directory name if any).'), 'f' => array('typ'=>$phartyp, 'val'=>NULL, 'inf'=>' Specifies the phar file to work on.'), 'h' => array('typ'=>'select', 'val'=>NULL, 'inf'=>' Selects the hash algorithmn.', 'select'=>array('md5'=>'MD5','sha1'=>'SHA1')), @@ -39,6 +39,16 @@ class PharCommand extends CLICommand 's' => array('typ'=>'file', 'val'=>NULL, 'inf'=>' Select the stub file.'), 'x' => array('typ'=>'regex', 'val'=>NULL, 'inf'=>' Regular expression for input files to exclude.'), ); + if (extension_loaded('zlib')) + { + $phar_args['c']['select']['gz'] = 'GZip compression'; + $phar_args['c']['select']['gzip'] = 'GZip compression'; + } + if (extension_loaded('bz2')) + { + $phar_args['c']['select']['bz2'] = 'BZip2 compression'; + $phar_args['c']['select']['bzip2'] = 'BZip2 compression'; + } $hash_avail = Phar::getSupportedSignatures(); if (in_array('SHA-256', $hash_avail)) { @@ -48,7 +58,6 @@ class PharCommand extends CLICommand { $phar_args['h']['select']['sha512'] = 'SHA512'; } - $args = array(); foreach($phar_args as $lkey => $cfg) { @@ -129,6 +138,30 @@ class PharCommand extends CLICommand return $arg; } + static function cli_arg_typ_compalg($arg, $cfg) + { + $arg = cli_cmd_typ_select($arg, $cfg); + switch($arg) + { + case 'auto': + if (extension_loaded('zlib')) + { + $arg = 'gz'; + } + else if (extension_loaded('bz2')) + { + $arg = 'bz2'; + } + else + { + $arg = '0'; + } + break; + case 'bz2': + } + return $arg; + } + static function cli_cmd_inf_pack() { return "Pack files into a PHAR archive.\n" @@ -407,30 +440,52 @@ class PharCommand extends CLICommand function cli_cmd_inf_compress() { - return "Compress or uncompress all files."; + return "Compress or uncompress all files or a selected entry."; } function cli_cmd_arg_compress() { - return self::phar_args('FC', 'phar'); + return self::phar_args('FCe', 'phar'); } function cli_cmd_run_compress() { - $phar = $this->args['f']['val']; + $phar = $this->args['f']['val']; + $entry = $this->args['e']['val']; switch($this->args['c']['val']) { case 'gz': case 'gzip': - $phar->compressAllFilesGZ(); + if (isset($entry)) + { + $phar[$entry]->setCompressedGZ(); + } + else + { + $phar->compressAllFilesGZ(); + } break; case 'bz2': case 'bzip2': - $phar->compressAllFilesBZIP2(); + if (isset($entry)) + { + $phar[$entry]->setCompressedBZIP2(); + } + else + { + $phar->compressAllFilesBZIP2(); + } break; default: - $phar->uncompressAllFiles(); + if (isset($entry)) + { + $phar[$entry]->setUncompressed(); + } + else + { + $phar->uncompressAllFiles(); + } break; } }