]> granicus.if.org Git - php/commitdiff
- Add support to include PHP_Archive when using pack
authorMarcus Boerger <helly@php.net>
Wed, 16 May 2007 22:56:43 +0000 (22:56 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 16 May 2007 22:56:43 +0000 (22:56 +0000)
ext/phar/phar.php
ext/phar/phar/phar.php
ext/phar/phar/pharcommand.inc

index f73c7bec86ab35e6da1fb97c79264099e7bf88e0..c294e5c93095a1886025dcb02ff5ee451d0ca225 100644 (file)
@@ -459,6 +459,7 @@ class PharCommand extends CLICommand
                        '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.'),
+                       'p' => array('typ'=>'file',    'val'=>NULL,                     'inf'=>'<loader> Location of PHP_Archive class file (pear list-files PHP_Archive).'),
                        's' => array('typ'=>'file',    'val'=>NULL,                     'inf'=>'<stub>   Select the stub file (excluded from list of input files/dirs).'),
                        'x' => array('typ'=>'regex',   'val'=>NULL,                     'inf'=>'<regex>  Regular expression for input files to exclude.'),
                        ''  => array('typ'=>'any',     'val'=>NULL,      'required'=>1, 'inf'=>'         Any number of input files and directories.'),
@@ -482,6 +483,7 @@ class PharCommand extends CLICommand
                $archive = $this->args['f']['val'];
                $hash    = $this->args['h']['val'];
                $regex   = $this->args['i']['val'];
+               $loader  = $this->args['p']['val'];
                $stub    = $this->args['s']['val'];
                $invregex= $this->args['x']['val'];
                $input   = $this->args['']['val'];
@@ -492,7 +494,25 @@ class PharCommand extends CLICommand
 
                if (isset($stub))
                {
-                       $phar->setStub(file_get_contents($stub));
+                       if (isset($loader))
+                       {
+                               $c = file_get_contents($stub);
+                               $s = '';
+                               if (substr($c,0,2) == '#!') {
+                                       $s.= substr($c,0,strpos($c, "\n")+1);
+                               }                               
+                               $s.= '<?php if (!class_exists("Phar",0) && !class_exists("PHP_Archive")) { ?>';
+                               $s.= file_get_contents($loader);
+                               $s.= '<?php } ?>';
+                               if (substr($c,0,1) == '#') {
+                                       $s.= substr($c,strpos($c, "\n")+1);
+                               }
+                               $phar->setStub($s);
+                       }
+                       else
+                       {
+                               $phar->setStub(file_get_contents($stub));
+                       }
                        $stub = new SplFileInfo($stub);
                }
 
index ca7f8d2d6173bbb998ddaba0a1c13dc84eb271a5..f117793595549158325ecfd3fef3ff86f44a4211 100755 (executable)
@@ -9,6 +9,20 @@
  *
  * Phar Command
  */
+
+if (!extension_loaded("phar"))
+{
+       if (!class_exists("PHP_Archive"))
+       {
+               echo "PHP_Archive not available.\n";
+               exit(1);
+       }
+       if (!class_exists("Phar"))
+       {
+               class Phar extends PHP_Archive {}
+       }
+}
+
 foreach(array("SPL", "Reflection", "Phar") as $ext)
 {
        if (!extension_loaded($ext))
index 975f9b0b05605cbd697e5921877c5ab9abd9361f..a4da19ee71203ee531149bfec78e5e6a3ac7a68a 100755 (executable)
@@ -74,6 +74,11 @@ class PharCommand extends CLICommand
                 'typ' => 'any',    
                 'val' => NULL,      
                 'inf' => '<meta>   Meta data to store with entry (serialized php data).'
+            ),
+            'p' => array(
+               'typ' => 'file',
+               'val' => NULL,
+               'inf' => '<loader> Location of PHP_Archive class file (pear list-files PHP_Archive).',
             ),
                        's' => array(
                 'typ' => 'file',   
@@ -213,7 +218,7 @@ class PharCommand extends CLICommand
 
        static function cli_cmd_arg_pack()
        {
-               $args = self::phar_args('AcFhisx', 'pharnew');
+               $args = self::phar_args('AcFhipsx', 'pharnew');
                $args[''] = array('typ'=>'any',     'val'=>NULL,      'required'=>1, 'inf'=>'         Any number of input files and directories. If -i is in use then ONLY files and matching thegiven regular expression are being packed. If -x is given then files matching that regular expression are NOT being packed.');
                return $args;
        }
@@ -235,6 +240,7 @@ class PharCommand extends CLICommand
                $archive = $this->args['f']['val'];
                $hash    = $this->args['h']['val'];
                $regex   = $this->args['i']['val'];
+               $loader  = $this->args['p']['val'];
                $stub    = $this->args['s']['val'];
                $invregex= $this->args['x']['val'];
                $input   = $this->args['']['val'];
@@ -245,7 +251,25 @@ class PharCommand extends CLICommand
 
                if (isset($stub))
                {
-                       $phar->setStub(file_get_contents($stub));
+                       if (isset($loader))
+                       {
+                               $c = file_get_contents($stub);
+                               $s = '';
+                               if (substr($c,0,2) == '#!') {
+                                       $s.= substr($c,0,strpos($c, "\n")+1);
+                               }                               
+                               $s.= '<?php if (!class_exists("Phar",0) && !class_exists("PHP_Archive")) { ?>';
+                               $s.= file_get_contents($loader);
+                               $s.= '<?php } ?>';
+                               if (substr($c,0,1) == '#') {
+                                       $s.= substr($c,strpos($c, "\n")+1);
+                               }
+                               $phar->setStub($s);
+                       }
+                       else
+                       {
+                               $phar->setStub(file_get_contents($stub));
+                       }
                        $stub = new SplFileInfo($stub);
                }