]> granicus.if.org Git - php/commitdiff
- Add auto compression mode to phar command and use it in Makefile.frag
authorMarcus Boerger <helly@php.net>
Tue, 15 May 2007 15:33:24 +0000 (15:33 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 15 May 2007 15:33:24 +0000 (15:33 +0000)
- Allow parameter types to be based on select type
- Allow to use compress command for selected entries

ext/phar/Makefile.frag
ext/phar/phar/clicommand.inc
ext/phar/phar/pharcommand.inc

index 3acfa940857768afbd3957f16a0195e74aa8ebaa..dadc024091aa366eca47e9ea893c153e40f84f1a 100755 (executable)
@@ -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
 
index f2faafccd9ec1d7fc4442f2079436755d32814e7..c829f19e1b36168472de9caa03bbe1be16fef48e 100755 (executable)
@@ -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)
index 9a2c2f86fe1dcb0d414979d917ec60026c75684d..a1a4bbe56977038a1af3c646b5e1457f8202b85e 100755 (executable)
@@ -30,7 +30,7 @@ class PharCommand extends CLICommand
        {
                $phar_args = array(
                        'a' => array('typ'=>'alias',  'val'=>'newphar', '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('0'=>'No compression','none'=>'No compression','auto'=>'Automatically select compression algorithm')),
                        'e' => array('typ'=>'entry',  'val'=>NULL,      'inf'=>'<entry>  Name of entry to work on (must include PHAR internal directory name if any).'),
                        'f' => array('typ'=>$phartyp, 'val'=>NULL,      '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')),
@@ -39,6 +39,16 @@ class PharCommand extends CLICommand
                        's' => array('typ'=>'file',   'val'=>NULL,      'inf'=>'<stub>   Select the stub file.'),
                        'x' => array('typ'=>'regex',  'val'=>NULL,      'inf'=>'<regex>  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;
                }
        }