'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.'),
$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'];
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);
}
*
* 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))
'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',
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;
}
$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'];
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);
}