]> granicus.if.org Git - php/commitdiff
- Fix compalg argument handling and merge it to preliminary phar command
authorMarcus Boerger <helly@php.net>
Tue, 15 May 2007 16:28:15 +0000 (16:28 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 15 May 2007 16:28:15 +0000 (16:28 +0000)
- Improve command info

ext/phar/phar.php
ext/phar/phar/pharcommand.inc

index d5d84568897bb9f7c5a17cc8b17112ae4d404af5..f73c7bec86ab35e6da1fb97c79264099e7bf88e0 100644 (file)
@@ -423,6 +423,29 @@ class PharCommand extends CLICommand
                }
        }
 
+       static function cli_arg_typ_compalg($arg, $cfg)
+       {
+               $arg = self::cli_arg_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;
+               }
+               return $arg;
+       }
+
        static function cli_cmd_inf_pack()
        {
                return "Pack files into a PHAR archive.";
@@ -432,7 +455,7 @@ class PharCommand extends CLICommand
        {
                return array(
                        'a' => array('typ'=>'alias',   'val'=>'newphar', 'required'=>1, 'inf'=>'<alias>  Provide an alias name for the phar file.'),
-                       'c' => array('typ'=>'select',  'val'=>NULL,                     'inf'=>'<algo>   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'=>'<algo>   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','auto'=>'Automatically select compression algorithm')),
                        'f' => array('typ'=>'pharnew', 'val'=>NULL,      'required'=>1, 'inf'=>'<file>   Specifies the phar file to work on.'),
                        'h' => array('typ'=>'select',  'val'=>NULL,                     'inf'=>'<method> Selects the hash algorithmn.', 'select'=>array('md5'=>'MD5','sha1'=>'SHA1','sha256'=>'SHA256','sha512'=>'SHA512')),
                        'i' => array('typ'=>'regex',   'val'=>NULL,                     'inf'=>'<regex>  Specifies a regular expression for input files.'),
index 02c012768a357b6525da91856374ee74c89d940f..a9ff152d5f4d7009f11ff587827de338926eab06 100755 (executable)
@@ -140,7 +140,7 @@ class PharCommand extends CLICommand
 
        static function cli_arg_typ_compalg($arg, $cfg)
        {
-               $arg = cli_cmd_typ_select($arg, $cfg);
+               $arg = self::cli_arg_typ_select($arg, $cfg);
                switch($arg)
                {
                case 'auto':
@@ -157,7 +157,6 @@ class PharCommand extends CLICommand
                                $arg = '0';
                        }
                        break;
-               case 'bz2':
                }
                return $arg;
        }
@@ -595,11 +594,11 @@ class PharCommand extends CLICommand
 
                if (!$hash)
                {
-                       $infos['Hash'] = 'NONE';
+                       $infos['Hash-type'] = 'NONE';
                }
                else
                {
-                       $infos['Hash Type'] = $hash['hash_type'];
+                       $infos['Hash-type'] = $hash['hash_type'];
                        $infos['Hash'] = $hash['hash'];
                }
 
@@ -609,6 +608,7 @@ class PharCommand extends CLICommand
                $ccount  = 0;
                $ucount  = 0;
                $mcount  = 0;
+               $compalg = array('GZ'=>0, 'BZ2'=>0);
 
                foreach(new RecursiveIteratorIterator($phar) as $ent)
                {
@@ -616,11 +616,22 @@ class PharCommand extends CLICommand
                        if ($ent->isCompressed())
                        {
                                $ccount++;
+                               $csize += $ent->getCompressedSize();
+                               if ($ent->isCompressedGZ())
+                               {
+                                       $compalg['GZ']++;
+                               }
+                               else if ($ent->isCompressedBZIP2())
+                               {
+                                       $compalg['BZ2']++;
+                               }
                        }
                        else
                        {
                                $ucount++;
+                               $csize += $ent->getSize();
                        }
+                       $usize += $ent->getSize();
                        if ($ent->hasMetadata())
                        {
                                $mcount++;
@@ -628,8 +639,12 @@ class PharCommand extends CLICommand
                }
 
                $infos['Entries'] = $count;
-               $infos['Compressed'] = $ccount;
-               $infos['Uncompressed'] = $ucount;
+               $infos['Uncompressed-files'] = $ucount;
+               $infos['Compressed-files'] = $ccount;
+               $infos['Compressed-gz'] = $compalg['GZ'];
+               $infos['Compressed-bz2'] = $compalg['BZ2'];
+               $infos['Uncompressed-size'] = $usize;
+               $infos['Compressed-size'] = $csize;
                $infos['Metadata'] = $mcount;
 
                $l = 0;