From: Marcus Boerger Date: Wed, 16 May 2007 22:56:43 +0000 (+0000) Subject: - Add support to include PHP_Archive when using pack X-Git-Tag: RELEASE_1_2_0~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d77c8b0fa7dbae79a25c1f3d522a9a7c01108253;p=php - Add support to include PHP_Archive when using pack --- diff --git a/ext/phar/phar.php b/ext/phar/phar.php index f73c7bec86..c294e5c930 100644 --- a/ext/phar/phar.php +++ b/ext/phar/phar.php @@ -459,6 +459,7 @@ class PharCommand extends CLICommand 'f' => array('typ'=>'pharnew', 'val'=>NULL, 'required'=>1, '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','sha256'=>'SHA256','sha512'=>'SHA512')), 'i' => array('typ'=>'regex', 'val'=>NULL, 'inf'=>' Specifies a regular expression for input files.'), + 'p' => array('typ'=>'file', 'val'=>NULL, 'inf'=>' Location of PHP_Archive class file (pear list-files PHP_Archive).'), 's' => array('typ'=>'file', 'val'=>NULL, 'inf'=>' Select the stub file (excluded from list of input files/dirs).'), 'x' => array('typ'=>'regex', 'val'=>NULL, 'inf'=>' 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.= ''; + $s.= file_get_contents($loader); + $s.= ''; + 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); } diff --git a/ext/phar/phar/phar.php b/ext/phar/phar/phar.php index ca7f8d2d61..f117793595 100755 --- a/ext/phar/phar/phar.php +++ b/ext/phar/phar/phar.php @@ -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)) diff --git a/ext/phar/phar/pharcommand.inc b/ext/phar/phar/pharcommand.inc index 975f9b0b05..a4da19ee71 100755 --- a/ext/phar/phar/pharcommand.inc +++ b/ext/phar/phar/pharcommand.inc @@ -74,6 +74,11 @@ class PharCommand extends CLICommand 'typ' => 'any', 'val' => NULL, 'inf' => ' Meta data to store with entry (serialized php data).' + ), + 'p' => array( + 'typ' => 'file', + 'val' => NULL, + 'inf' => ' 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.= ''; + $s.= file_get_contents($loader); + $s.= ''; + 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); }