Browse Source

- Consistency rocks: Make all lines start with tabs for indentation

# Just as anythign else we do.
# Also saves about ~0.5k in phar.phar
PECL
Marcus Boerger 18 years ago
parent
commit
152e4273d1
  1. 70
      ext/phar/makestub.php
  2. 50
      ext/phar/package.php
  3. 712
      ext/phar/phar/clicommand.inc
  4. 2
      ext/phar/phar/directorytreeiterator.inc
  5. 40
      ext/phar/phar/phar.php
  6. 2918
      ext/phar/phar/pharcommand.inc
  7. 564
      ext/phar/shortarc.php

70
ext/phar/makestub.php

@ -4,18 +4,18 @@ $s = str_replace("\r", '', file_get_contents(dirname(__FILE__) . '/shortarc.php'
$s .= "\nExtract_Phar::go();\n__HALT_COMPILER();";
$news = '';
foreach (token_get_all($s) as $token) {
if (is_array($token)) {
if ($token[0] == T_COMMENT) {
$token[1] = '';
}
if ($token[0] == T_WHITESPACE) {
$n = str_repeat("\n", substr_count($token[1], "\n"));
$token[1] = strlen($n) ? $n : ' ';
}
$news .= $token[1];
} else {
$news .= $token;
}
if (is_array($token)) {
if ($token[0] == T_COMMENT) {
$token[1] = '';
}
if ($token[0] == T_WHITESPACE) {
$n = str_repeat("\n", substr_count($token[1], "\n"));
$token[1] = strlen($n) ? $n : ' ';
}
$news .= $token[1];
} else {
$news .= $token;
}
}
$s = $news . ' ?>';
$slen = strlen($s) - strlen('index.php') - strlen("000");
@ -57,50 +57,50 @@ $s1split = str_split($s1, 2046);
$s3split = str_split($s3, 2046);
$took = false;
foreach ($s1split as $i => $chunk) {
if ($took) {
$s1split[$i] = substr($chunk, 1);
$took = false;
}
if ($chunk[strlen($chunk) - 1] == '\\') {
$s1split[$i] .= $s1split[$i + 1][0];
$took = true;
}
if ($took) {
$s1split[$i] = substr($chunk, 1);
$took = false;
}
if ($chunk[strlen($chunk) - 1] == '\\') {
$s1split[$i] .= $s1split[$i + 1][0];
$took = true;
}
}
foreach ($s3split as $i => $chunk) {
if ($took) {
$s3split[$i] = substr($chunk, 1);
$took = false;
}
if ($chunk[strlen($chunk) - 1] == '\\') {
$s3split[$i] .= $s3split[$i + 1][0];
$took = true;
}
if ($took) {
$s3split[$i] = substr($chunk, 1);
$took = false;
}
if ($chunk[strlen($chunk) - 1] == '\\') {
$s3split[$i] .= $s3split[$i + 1][0];
$took = true;
}
}
$stub .= "\tstatic const char newstub0[] = \"" . $webs . '";
';
foreach ($s1split as $i => $chunk) {
$s1count = $i + 1;
$stub .= "\tstatic const char newstub1_" . $i . '[] = "' . $chunk . '";
$s1count = $i + 1;
$stub .= "\tstatic const char newstub1_" . $i . '[] = "' . $chunk . '";
';
}
$stub .= "\tstatic const char newstub2[] = \"" . $s2 . "\";
";
foreach ($s3split as $i => $chunk) {
$s3count = $i + 1;
$stub .= "\tstatic const char newstub3_" . $i . '[] = "' . $chunk . '";
$s3count = $i + 1;
$stub .= "\tstatic const char newstub3_" . $i . '[] = "' . $chunk . '";
';
}
$stub .= "\n\tstatic const int newstub_len = " . $slen . ";
\t*len = spprintf(stub, name_len + web_len + newstub_len, \"%s%s" . str_repeat('%s', $s1count) . '%s%s%d'
. str_repeat('%s', $s3count) . '", newstub0, web';
. str_repeat('%s', $s3count) . '", newstub0, web';
foreach ($s1split as $i => $unused) {
$stub .= ', newstub1_' . $i;
$stub .= ', newstub1_' . $i;
}
$stub .= ', index_php, newstub2';
$stub .= ", name_len + web_len + newstub_len";
foreach ($s3split as $i => $unused) {
$stub .= ', newstub3_' . $i;
$stub .= ', newstub3_' . $i;
}
$stub .= ");
}";

50
ext/phar/package.php

@ -53,29 +53,29 @@ require_once 'PEAR/PackageFileManager2.php';
PEAR::setErrorHandling(PEAR_ERROR_DIE);
$options = array(
'filelistgenerator' => 'CVS',
'changelogoldtonew' => false,
'simpleoutput' => true,
'baseinstalldir' => '/',
'packagedirectory' => dirname(__FILE__),
'packagefile' => 'package.xml',
'clearcontents' => true,
'ignore' => array('package*.php', 'package*.xml'),
'dir_roles' => array(
'docs' => 'doc',
'examples' => 'doc',
'tests' => 'test',
'phar' => 'src',
),
'exceptions' => array(
'CREDITS' => 'doc',
'EXPERIMENTAL' => 'doc',
'LICENSE' => 'doc',
'Makefile.frag' => 'src',
'phar_path_check.re' => 'src',
'TODO' => 'doc',
'phar.phar' => 'script',
),
'filelistgenerator' => 'CVS',
'changelogoldtonew' => false,
'simpleoutput' => true,
'baseinstalldir' => '/',
'packagedirectory' => dirname(__FILE__),
'packagefile' => 'package.xml',
'clearcontents' => true,
'ignore' => array('package*.php', 'package*.xml'),
'dir_roles' => array(
'docs' => 'doc',
'examples' => 'doc',
'tests' => 'test',
'phar' => 'src',
),
'exceptions' => array(
'CREDITS' => 'doc',
'EXPERIMENTAL' => 'doc',
'LICENSE' => 'doc',
'Makefile.frag' => 'src',
'phar_path_check.re' => 'src',
'TODO' => 'doc',
'phar.phar' => 'script',
),
);
$package = PEAR_PackageFileManager2::importOptions(dirname(__FILE__) . '/package.xml', $options);
@ -100,9 +100,9 @@ $package->setNotes("\n$notes\n");
$package->generateContents();
if (isset($_GET['make']) || (isset($_SERVER['argv']) && @$_SERVER['argv'][1] == 'make')) {
$package->writePackageFile();
$package->writePackageFile();
} else {
$package->debugPackageFile();
$package->debugPackageFile();
}
?>

712
ext/phar/phar/clicommand.inc

@ -16,362 +16,362 @@
*/
abstract class CLICommand
{
protected $argc;
protected $argv;
protected $cmds = array();
protected $args = array();
protected $typs = array();
function __construct($argc, array $argv)
{
$this->argc = $argc;
$this->argv = $argv;
$this->cmds = self::getCommands($this);
$this->typs = self::getArgTyps($this);
if ($argc < 2) {
self::error("No command given, check ${argv[0]} help\n");
} elseif (!isset($this->cmds[$argv[1]]['run'])) {
self::error("Unknown command '${argv[1]}', check ${argv[0]} help\n");
} else {
$command = $argv[1];
}
if (isset($this->cmds[$command]['arg'])) {
$this->args = call_user_func(array($this, $this->cmds[$command]['arg']));
$i = 1;
$missing = false;
while (++$i < $argc) {
if ($argv[$i][0] == '-') {
if (strlen($argv[$i]) == 2 && isset($this->args[$argv[$i][1]])) {
$arg = $argv[$i][1];
if (++$i >= $argc) {
self::error("Missing argument to parameter '$arg' of command '$command', check ${argv[0]} help\n");
} else {
$this->args[$arg]['val'] = $this->checkArgTyp($arg, $i, $argc, $argv);
}
} else {
self::error("Unknown parameter '${argv[$i]}' to command $command, check ${argv[0]} help\n");
}
} else {
break;
}
}
if (isset($this->args[''])) {
if ($i >= $argc) {
if (isset($this->args['']['require']) && $this->args['']['require']) {
self::error("Missing default trailing arguments to command $command, check ${argv[0]} help\n");
}
} else {
$this->args['']['val'] = array();
while($i < $argc) {
$this->args['']['val'][] = $argv[$i++];
}
}
} else if ($i < $argc) {
self::error("Unexpected default arguments to command $command, check ${argv[0]} help\n");
}
foreach($this->args as $arg => $inf) {
if (strlen($arg) && !isset($inf['val']) && isset($inf['required']) && $inf['required']) {
$missing .= "Missing parameter '-$arg' to command $command, check ${argv[0]} help\n";
}
}
if (strlen($missing))
{
self::error($missing);
}
}
call_user_func(array($this, $this->cmds[$command]['run']), $this->args);
}
static function notice ($msg)
{
fprintf(STDERR, $msg);
}
static function error ($msg, $exit_code = 1)
{
self::notice($msg);
exit($exit_code);
}
function checkArgTyp($arg, $i, $argc, $argv)
{
$typ = $this->args[$arg]['typ'];
if (isset($this->typs[$typ]['typ'])) {
return call_user_func(array($this, $this->typs[$typ]['typ']), $argv[$i], $this->args[$arg], $arg);
} else {
return $argv[$i];
}
}
static function getSubFuncs(CLICommand $cmdclass, $prefix, array $subs)
{
$a = array();
$r = new ReflectionClass($cmdclass);
$l = strlen($prefix);
foreach($r->getMethods() as $m)
{
if (substr($m->name, 0, $l) == $prefix)
{
foreach($subs as $sub)
{
$what = substr($m->name, $l+strlen($sub)+1);
$func = $prefix . $sub . '_' . $what;
$what = str_replace('_', '-', $what);
if ($r->hasMethod($func))
{
if (!isset($a[$what]))
{
$a[$what] = array();
}
$a[$what][$sub] = /*$m->class . '::' .*/ $func;
}
}
}
}
return $a;
}
static function getCommands(CLICommand $cmdclass)
{
return self::getSubFuncs($cmdclass, 'cli_cmd_', array('arg','inf','run'));
}
static function getArgTyps(CLICommand $cmdclass)
{
return self::getSubFuncs($cmdclass, 'cli_arg_', array('typ'));
}
static function cli_arg_typ_bool($arg, $cfg, $key)
{
return (bool)$arg;
}
static function cli_arg_typ_int($arg, $cfg, $key)
{
if ((int)$arg != $arg) {
self::error("Argument to -$key must be an integer.\n");
}
return (int)$arg;
}
static function cli_arg_typ_regex($arg, $cfg, $key)
{
if (strlen($arg))
{
if (strlen($arg) > 1 && $arg[0] == $arg[strlen($arg)-1] && strpos('/,', $arg) !== false)
{
return $arg;
}
else
{
return '/' . $arg . '/';
}
}
else
{
return NULL;
}
}
static function cli_arg_typ_select($arg, $cfg, $key)
{
if (!in_array($arg, array_keys($cfg['select']))) {
self::error("Parameter value '$arg' not one of '" . join("', '", array_keys($cfg['select'])) . "'.\n");
}
return $arg;
}
static function cli_arg_typ_dir($arg, $cfg, $key)
{
$f = realpath($arg);
if ($f===false || !file_exists($f) || !is_dir($f)) {
self::error("Requested path '$arg' does not exist.\n");
}
return $f;
}
static function cli_arg_typ_file($arg)
{
$f = new SplFileInfo($arg);
$f = $f->getRealPath();
if ($f===false || !file_exists($f))
{
echo "Requested file '$arg' does not exist.\n";
exit(1);
}
return $f;
}
static function cli_arg_typ_filenew($arg, $cfg, $key)
{
$d = dirname($arg);
$f = realpath($d);
if ($f === false) {
self::error("Path for file '$arg' does not exist.\n");
}
return $f . '/' . basename($arg);
}
static function cli_arg_typ_filecont($arg, $cfg, $key)
{
return file_get_contents(self::cli_arg_typ_file($arg, $cfg, $key));
}
function cli_get_SP2($l1, $arg_inf)
{
return str_repeat(' ', $l1 + 2 + 4 + 8);
}
function cli_get_SP3($l1, $l2, $arg_inf)
{
return str_repeat(' ', $l1 + 2 + 4 + 8 + 2 + $l2 + 2);
}
static function cli_cmd_inf_help()
{
return "This help or help for a selected command.";
}
private function cli_wordwrap($what, $l, $sp)
{
$p = max(79 - $l, 40); // minimum length for paragraph
$b = substr($what, 0, $l); // strip out initial $l
$r = substr($what, $l); // remainder
$r = str_replace("\n", "\n".$sp, $r); // in remainder replace \n's
return $b . wordwrap($r, $p, "\n".$sp);
}
private function cli_help_get_args($func, $l, $sp, $required)
{
$inf = "";
foreach(call_user_func($func, $l, $sp) as $arg => $conf)
{
if ((isset($conf['required']) && $conf['required']) != $required)
{
continue;
}
if (strlen($arg))
{
$arg = "-$arg ";
}
else
{
$arg = "... ";
}
$sp2 = $this->cli_get_SP2($l, $inf);
$l2 = strlen($sp2);
$inf .= $this->cli_wordwrap($sp . $arg . $conf['inf'], $l2, $sp2) . "\n";
if (isset($conf['select']) && count($conf['select']))
{
$ls = 0;
foreach($conf['select'] as $opt => $what)
{
$ls = max($ls, strlen($opt));
}
$sp3 = $this->cli_get_SP3($l, $ls, $inf);
$l3 = strlen($sp3);
foreach($conf['select'] as $opt => $what)
{
$inf .= $this->cli_wordwrap($sp2 . " " . sprintf("%-${ls}s ", $opt) . $what, $l3, $sp3) . "\n";
}
}
}
if (strlen($inf))
{
if ($required)
{
return $sp . "Required arguments:\n\n" . $inf;
}
else
{
return $sp . "Optional arguments:\n\n". $inf;
}
}
}
function cli_cmd_arg_help()
{
return array('' => array('typ'=>'any','val'=>NULL,'inf'=>'Optional command to retrieve help for.'));
}
function cli_cmd_run_help()
{
$argv = $this->argv;
$which = $this->args['']['val'];
if (isset($which))
{
if (count($which) != 1) {
self::error("More than one command given.\n");
}
$which = $which[0];
if (!array_key_exists($which, $this->cmds)) {
if (strtolower($which) == 'commands') {
self::cli_cmd_run_help_list();
exit(0);
}
self::error("Unknown command, cannot retrieve help.\n");
}
$l = strlen($which);
$cmds = array($which => $this->cmds[$which]);
} else {
echo "\n$argv[0] <command> [options]\n\n";
$l = 0;
ksort($this->cmds);
foreach($this->cmds as $name => $funcs) {
$l = max($l, strlen($name));
}
$inf = "Commands:";
$lst = "";
$ind = strlen($inf) + 1;
foreach($this->cmds as $name => $funcs)
{
$lst .= ' ' . $name;
}
echo $this->cli_wordwrap($inf.$lst, $ind, str_repeat(' ', $ind)) . "\n\n";
$cmds = $this->cmds;
}
$sp = str_repeat(' ', $l + 2);
foreach($cmds as $name => $funcs)
{
$inf = $name . substr($sp, strlen($name));
if (isset($funcs['inf']))
{
$inf .= $this->cli_wordwrap(call_user_func(array($this, $funcs['inf'])), $l, $sp) . "\n";
if (isset($funcs['arg']))
{
$inf .= "\n";
$inf .= $this->cli_help_get_args(array($this, $funcs['arg']), $l, $sp, true);
$inf .= "\n";
$inf .= $this->cli_help_get_args(array($this, $funcs['arg']), $l, $sp, false);
}
}
echo "$inf\n\n";
}
exit(0);
}
static function cli_cmd_inf_help_list()
{
return "Lists available commands.";
}
function cli_cmd_run_help_list()
{
ksort($this->cmds);
echo join(' ', array_keys($this->cmds)) . "\n";
}
protected $argc;
protected $argv;
protected $cmds = array();
protected $args = array();
protected $typs = array();
function __construct($argc, array $argv)
{
$this->argc = $argc;
$this->argv = $argv;
$this->cmds = self::getCommands($this);
$this->typs = self::getArgTyps($this);
if ($argc < 2) {
self::error("No command given, check ${argv[0]} help\n");
} elseif (!isset($this->cmds[$argv[1]]['run'])) {
self::error("Unknown command '${argv[1]}', check ${argv[0]} help\n");
} else {
$command = $argv[1];
}
if (isset($this->cmds[$command]['arg'])) {
$this->args = call_user_func(array($this, $this->cmds[$command]['arg']));
$i = 1;
$missing = false;
while (++$i < $argc) {
if ($argv[$i][0] == '-') {
if (strlen($argv[$i]) == 2 && isset($this->args[$argv[$i][1]])) {
$arg = $argv[$i][1];
if (++$i >= $argc) {
self::error("Missing argument to parameter '$arg' of command '$command', check ${argv[0]} help\n");
} else {
$this->args[$arg]['val'] = $this->checkArgTyp($arg, $i, $argc, $argv);
}
} else {
self::error("Unknown parameter '${argv[$i]}' to command $command, check ${argv[0]} help\n");
}
} else {
break;
}
}
if (isset($this->args[''])) {
if ($i >= $argc) {
if (isset($this->args['']['require']) && $this->args['']['require']) {
self::error("Missing default trailing arguments to command $command, check ${argv[0]} help\n");
}
} else {
$this->args['']['val'] = array();
while($i < $argc) {
$this->args['']['val'][] = $argv[$i++];
}
}
} else if ($i < $argc) {
self::error("Unexpected default arguments to command $command, check ${argv[0]} help\n");
}
foreach($this->args as $arg => $inf) {
if (strlen($arg) && !isset($inf['val']) && isset($inf['required']) && $inf['required']) {
$missing .= "Missing parameter '-$arg' to command $command, check ${argv[0]} help\n";
}
}
if (strlen($missing))
{
self::error($missing);
}
}
call_user_func(array($this, $this->cmds[$command]['run']), $this->args);
}
static function notice ($msg)
{
fprintf(STDERR, $msg);
}
static function error ($msg, $exit_code = 1)
{
self::notice($msg);
exit($exit_code);
}
function checkArgTyp($arg, $i, $argc, $argv)
{
$typ = $this->args[$arg]['typ'];
if (isset($this->typs[$typ]['typ'])) {
return call_user_func(array($this, $this->typs[$typ]['typ']), $argv[$i], $this->args[$arg], $arg);
} else {
return $argv[$i];
}
}
static function getSubFuncs(CLICommand $cmdclass, $prefix, array $subs)
{
$a = array();
$r = new ReflectionClass($cmdclass);
$l = strlen($prefix);
foreach($r->getMethods() as $m)
{
if (substr($m->name, 0, $l) == $prefix)
{
foreach($subs as $sub)
{
$what = substr($m->name, $l+strlen($sub)+1);
$func = $prefix . $sub . '_' . $what;
$what = str_replace('_', '-', $what);
if ($r->hasMethod($func))
{
if (!isset($a[$what]))
{
$a[$what] = array();
}
$a[$what][$sub] = /*$m->class . '::' .*/ $func;
}
}
}
}
return $a;
}
static function getCommands(CLICommand $cmdclass)
{
return self::getSubFuncs($cmdclass, 'cli_cmd_', array('arg','inf','run'));
}
static function getArgTyps(CLICommand $cmdclass)
{
return self::getSubFuncs($cmdclass, 'cli_arg_', array('typ'));
}
static function cli_arg_typ_bool($arg, $cfg, $key)
{
return (bool)$arg;
}
static function cli_arg_typ_int($arg, $cfg, $key)
{
if ((int)$arg != $arg) {
self::error("Argument to -$key must be an integer.\n");
}
return (int)$arg;
}
static function cli_arg_typ_regex($arg, $cfg, $key)
{
if (strlen($arg))
{
if (strlen($arg) > 1 && $arg[0] == $arg[strlen($arg)-1] && strpos('/,', $arg) !== false)
{
return $arg;
}
else
{
return '/' . $arg . '/';
}
}
else
{
return NULL;
}
}
static function cli_arg_typ_select($arg, $cfg, $key)
{
if (!in_array($arg, array_keys($cfg['select']))) {
self::error("Parameter value '$arg' not one of '" . join("', '", array_keys($cfg['select'])) . "'.\n");
}
return $arg;
}
static function cli_arg_typ_dir($arg, $cfg, $key)
{
$f = realpath($arg);
if ($f===false || !file_exists($f) || !is_dir($f)) {
self::error("Requested path '$arg' does not exist.\n");
}
return $f;
}
static function cli_arg_typ_file($arg)
{
$f = new SplFileInfo($arg);
$f = $f->getRealPath();
if ($f===false || !file_exists($f))
{
echo "Requested file '$arg' does not exist.\n";
exit(1);
}
return $f;
}
static function cli_arg_typ_filenew($arg, $cfg, $key)
{
$d = dirname($arg);
$f = realpath($d);
if ($f === false) {
self::error("Path for file '$arg' does not exist.\n");
}
return $f . '/' . basename($arg);
}
static function cli_arg_typ_filecont($arg, $cfg, $key)
{
return file_get_contents(self::cli_arg_typ_file($arg, $cfg, $key));
}
function cli_get_SP2($l1, $arg_inf)
{
return str_repeat(' ', $l1 + 2 + 4 + 8);
}
function cli_get_SP3($l1, $l2, $arg_inf)
{
return str_repeat(' ', $l1 + 2 + 4 + 8 + 2 + $l2 + 2);
}
static function cli_cmd_inf_help()
{
return "This help or help for a selected command.";
}
private function cli_wordwrap($what, $l, $sp)
{
$p = max(79 - $l, 40); // minimum length for paragraph
$b = substr($what, 0, $l); // strip out initial $l
$r = substr($what, $l); // remainder
$r = str_replace("\n", "\n".$sp, $r); // in remainder replace \n's
return $b . wordwrap($r, $p, "\n".$sp);
}
private function cli_help_get_args($func, $l, $sp, $required)
{
$inf = "";
foreach(call_user_func($func, $l, $sp) as $arg => $conf)
{
if ((isset($conf['required']) && $conf['required']) != $required)
{
continue;
}
if (strlen($arg))
{
$arg = "-$arg ";
}
else
{
$arg = "... ";
}
$sp2 = $this->cli_get_SP2($l, $inf);
$l2 = strlen($sp2);
$inf .= $this->cli_wordwrap($sp . $arg . $conf['inf'], $l2, $sp2) . "\n";
if (isset($conf['select']) && count($conf['select']))
{
$ls = 0;
foreach($conf['select'] as $opt => $what)
{
$ls = max($ls, strlen($opt));
}
$sp3 = $this->cli_get_SP3($l, $ls, $inf);
$l3 = strlen($sp3);
foreach($conf['select'] as $opt => $what)
{
$inf .= $this->cli_wordwrap($sp2 . " " . sprintf("%-${ls}s ", $opt) . $what, $l3, $sp3) . "\n";
}
}
}
if (strlen($inf))
{
if ($required)
{
return $sp . "Required arguments:\n\n" . $inf;
}
else
{
return $sp . "Optional arguments:\n\n". $inf;
}
}
}
function cli_cmd_arg_help()
{
return array('' => array('typ'=>'any','val'=>NULL,'inf'=>'Optional command to retrieve help for.'));
}
function cli_cmd_run_help()
{
$argv = $this->argv;
$which = $this->args['']['val'];
if (isset($which))
{
if (count($which) != 1) {
self::error("More than one command given.\n");
}
$which = $which[0];
if (!array_key_exists($which, $this->cmds)) {
if (strtolower($which) == 'commands') {
self::cli_cmd_run_help_list();
exit(0);
}
self::error("Unknown command, cannot retrieve help.\n");
}
$l = strlen($which);
$cmds = array($which => $this->cmds[$which]);
} else {
echo "\n$argv[0] <command> [options]\n\n";
$l = 0;
ksort($this->cmds);
foreach($this->cmds as $name => $funcs) {
$l = max($l, strlen($name));
}
$inf = "Commands:";
$lst = "";
$ind = strlen($inf) + 1;
foreach($this->cmds as $name => $funcs)
{
$lst .= ' ' . $name;
}
echo $this->cli_wordwrap($inf.$lst, $ind, str_repeat(' ', $ind)) . "\n\n";
$cmds = $this->cmds;
}
$sp = str_repeat(' ', $l + 2);
foreach($cmds as $name => $funcs)
{
$inf = $name . substr($sp, strlen($name));
if (isset($funcs['inf']))
{
$inf .= $this->cli_wordwrap(call_user_func(array($this, $funcs['inf'])), $l, $sp) . "\n";
if (isset($funcs['arg']))
{
$inf .= "\n";
$inf .= $this->cli_help_get_args(array($this, $funcs['arg']), $l, $sp, true);
$inf .= "\n";
$inf .= $this->cli_help_get_args(array($this, $funcs['arg']), $l, $sp, false);
}
}
echo "$inf\n\n";
}
exit(0);
}
static function cli_cmd_inf_help_list()
{
return "Lists available commands.";
}
function cli_cmd_run_help_list()
{
ksort($this->cmds);
echo join(' ', array_keys($this->cmds)) . "\n";
}
}
?>

2
ext/phar/phar/directorytreeiterator.inc

@ -40,7 +40,7 @@ class DirectoryTreeIterator extends RecursiveIteratorIterator
$tree .= $this->getSubIterator($l)->hasNext() ? '| ' : ' ';
}
return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-')
. $this->getSubIterator($l)->__toString();
. $this->getSubIterator($l)->__toString();
}
/** Aggregates the inner iterator

40
ext/phar/phar/phar.php

@ -14,38 +14,38 @@ if (!extension_loaded('phar'))
{
if (!class_exists('PHP_Archive', 0))
{
echo "Neither Extension Phar nor class PHP_Archive are available.\n";
exit(1);
}
if (!in_array('phar', stream_get_wrappers()))
{
stream_wrapper_register('phar', 'PHP_Archive');
}
if (!class_exists('Phar',0)) {
require 'phar://'.__FILE__.'/phar.inc';
}
echo "Neither Extension Phar nor class PHP_Archive are available.\n";
exit(1);
}
if (!in_array('phar', stream_get_wrappers()))
{
stream_wrapper_register('phar', 'PHP_Archive');
}
if (!class_exists('Phar',0)) {
require 'phar://'.__FILE__.'/phar.inc';
}
}
foreach(array("SPL", "Reflection") as $ext)
{
if (!extension_loaded($ext))
{
echo "$argv[0] requires PHP extension $ext.\n";
exit(1);
}
if (!extension_loaded($ext))
{
echo "$argv[0] requires PHP extension $ext.\n";
exit(1);
}
}
function command_include($file)
{
$file = 'phar://' . __FILE__ . '/' . $file;
if (file_exists($file)) {
include($file);
}
$file = 'phar://' . __FILE__ . '/' . $file;
if (file_exists($file)) {
include($file);
}
}
function command_autoload($classname)
{
command_include(strtolower($classname) . '.inc');
command_include(strtolower($classname) . '.inc');
}
Phar::mapPhar();

2918
ext/phar/phar/pharcommand.inc
File diff suppressed because it is too large
View File

564
ext/phar/shortarc.php

@ -3,293 +3,293 @@
$web = '000';
if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
Phar::interceptFileFuncs();
set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
Phar::webPhar(null, $web);
include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
return;
Phar::interceptFileFuncs();
set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
Phar::webPhar(null, $web);
include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
return;
}
if (@(isset($_SERVER['REQUEST_URI']) && isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'POST'))) {
Extract_Phar::go(true);
$mimes = array(
'phps' => 2,
'c' => 'text/plain',
'cc' => 'text/plain',
'cpp' => 'text/plain',
'c++' => 'text/plain',
'dtd' => 'text/plain',
'h' => 'text/plain',
'log' => 'text/plain',
'rng' => 'text/plain',
'txt' => 'text/plain',
'xsd' => 'text/plain',
'php' => 1,
'inc' => 1,
'avi' => 'video/avi',
'bmp' => 'image/bmp',
'css' => 'text/css',
'gif' => 'image/gif',
'htm' => 'text/html',
'html' => 'text/html',
'htmls' => 'text/html',
'ico' => 'image/x-ico',
'jpe' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'js' => 'application/x-javascript',
'midi' => 'audio/midi',
'mid' => 'audio/midi',
'mod' => 'audio/mod',
'mov' => 'movie/quicktime',
'mp3' => 'audio/mp3',
'mpg' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'pdf' => 'application/pdf',
'png' => 'image/png',
'swf' => 'application/shockwave-flash',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'wav' => 'audio/wav',
'xbm' => 'image/xbm',
'xml' => 'text/xml',
);
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$basename = basename(__FILE__);
if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
chdir(Extract_Phar::$temp);
include $web;
return;
}
$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
if (!$pt || $pt == '/') {
$pt = $web;
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
exit;
}
$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
header('HTTP/1.0 404 Not Found');
echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
exit;
}
$b = pathinfo($a);
if (!isset($b['extension'])) {
header('Content-Type: text/plain');
header('Content-Length: ' . filesize($a));
readfile($a);
exit;
}
if (isset($mimes[$b['extension']])) {
if ($mimes[$b['extension']] === 1) {
include $a;
exit;
}
if ($mimes[$b['extension']] === 2) {
highlight_file($a);
exit;
}
header('Content-Type: ' .$mimes[$b['extension']]);
header('Content-Length: ' . filesize($a));
readfile($a);
exit;
}
Extract_Phar::go(true);
$mimes = array(
'phps' => 2,
'c' => 'text/plain',
'cc' => 'text/plain',
'cpp' => 'text/plain',
'c++' => 'text/plain',
'dtd' => 'text/plain',
'h' => 'text/plain',
'log' => 'text/plain',
'rng' => 'text/plain',
'txt' => 'text/plain',
'xsd' => 'text/plain',
'php' => 1,
'inc' => 1,
'avi' => 'video/avi',
'bmp' => 'image/bmp',
'css' => 'text/css',
'gif' => 'image/gif',
'htm' => 'text/html',
'html' => 'text/html',
'htmls' => 'text/html',
'ico' => 'image/x-ico',
'jpe' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'js' => 'application/x-javascript',
'midi' => 'audio/midi',
'mid' => 'audio/midi',
'mod' => 'audio/mod',
'mov' => 'movie/quicktime',
'mp3' => 'audio/mp3',
'mpg' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'pdf' => 'application/pdf',
'png' => 'image/png',
'swf' => 'application/shockwave-flash',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'wav' => 'audio/wav',
'xbm' => 'image/xbm',
'xml' => 'text/xml',
);
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
$basename = basename(__FILE__);
if (!strpos($_SERVER['REQUEST_URI'], $basename)) {
chdir(Extract_Phar::$temp);
include $web;
return;
}
$pt = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], $basename) + strlen($basename));
if (!$pt || $pt == '/') {
$pt = $web;
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $_SERVER['REQUEST_URI'] . '/' . $pt);
exit;
}
$a = realpath(Extract_Phar::$temp . DIRECTORY_SEPARATOR . $pt);
if (!$a || strlen(dirname($a)) < strlen(Extract_Phar::$temp)) {
header('HTTP/1.0 404 Not Found');
echo "<html>\n <head>\n <title>File Not Found<title>\n </head>\n <body>\n <h1>404 - File ", $pt, " Not Found</h1>\n </body>\n</html>";
exit;
}
$b = pathinfo($a);
if (!isset($b['extension'])) {
header('Content-Type: text/plain');
header('Content-Length: ' . filesize($a));
readfile($a);
exit;
}
if (isset($mimes[$b['extension']])) {
if ($mimes[$b['extension']] === 1) {
include $a;
exit;
}
if ($mimes[$b['extension']] === 2) {
highlight_file($a);
exit;
}
header('Content-Type: ' .$mimes[$b['extension']]);
header('Content-Length: ' . filesize($a));
readfile($a);
exit;
}
}
class Extract_Phar
{
static $temp;
static $origdir;
const GZ = 0x1000;
const BZ2 = 0x2000;
const MASK = 0x3000;
const START = 'index.php';
const LEN = XXXX;
static function go($return = false)
{
$fp = fopen(__FILE__, 'rb');
fseek($fp, self::LEN);
$L = unpack('V', $a = (binary)fread($fp, 4));
$m = (binary)'';
do {
$read = 8192;
if ($L[1] - strlen($m) < 8192) {
$read = $L[1] - strlen($m);
}
$last = (binary)fread($fp, $read);
$m .= $last;
} while (strlen($last) && strlen($m) < $L[1]);
if (strlen($m) < $L[1]) {
die('ERROR: manifest length read was "' .
strlen($m) .'" should be "' .
$L[1] . '"');
}
$info = self::_unpack($m);
$f = $info['c'];
if ($f & self::GZ) {
if (!function_exists('gzinflate')) {
die('Error: zlib extension is not enabled -' .
' gzinflate() function needed for zlib-compressed .phars');
}
}
if ($f & self::BZ2) {
if (!function_exists('bzdecompress')) {
die('Error: bzip2 extension is not enabled -' .
' bzdecompress() function needed for bz2-compressed .phars');
}
}
$temp = self::tmpdir();
if (!$temp || !is_writable($temp)) {
$sessionpath = session_save_path();
if (strpos ($sessionpath, ";") !== false)
$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
die('Could not locate temporary directory to extract phar');
}
$temp = $sessionpath;
}
$temp .= '/pharextract/'.basename(__FILE__, '.phar');
self::$temp = $temp;
self::$origdir = getcwd();
@mkdir($temp, 0777, true);
$temp = realpath($temp);
if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
self::_removeTmpFiles($temp, getcwd());
@mkdir($temp, 0777, true);
@file_put_contents($temp . '/' . md5_file(__FILE__), '');
foreach ($info['m'] as $path => $file) {
$a = !file_exists(dirname($temp . '/' . $path));
@mkdir(dirname($temp . '/' . $path), 0777, true);
clearstatcache();
if ($path[strlen($path) - 1] == '/') {
@mkdir($temp . '/' . $path, 0777);
} else {
file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
@chmod($temp . '/' . $path, 0666);
}
}
}
chdir($temp);
if (!$return) {
include self::START;
}
}
static function tmpdir()
{
if (strpos(PHP_OS, 'WIN') !== false) {
if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
return $var;
}
if (is_dir('/temp') || mkdir('/temp')) {
return realpath('/temp');
}
return false;
}
if ($var = getenv('TMPDIR')) {
return $var;
}
return realpath('/tmp');
}
static function _unpack($m)
{
$info = unpack('V', substr($m, 0, 4));
// skip API version, phar flags, alias, metadata
$l = unpack('V', substr($m, 10, 4));
$m = substr($m, 14 + $l[1]);
$s = unpack('V', substr($m, 0, 4));
$o = 0;
$start = 4 + $s[1];
$ret['c'] = 0;
for ($i = 0; $i < $info[1]; $i++) {
// length of the file name
$len = unpack('V', substr($m, $start, 4));
$start += 4;
// file name
$savepath = substr($m, $start, $len[1]);
$start += $len[1];
// retrieve manifest data:
// 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags
// 5 = metadata length
$ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
& 0xffffffff);
$ret['m'][$savepath][7] = $o;
$o += $ret['m'][$savepath][2];
$start += 24 + $ret['m'][$savepath][5];
$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
}
return $ret;
}
static function extractFile($path, $entry, $fp)
{
$data = '';
$c = $entry[2];
while ($c) {
if ($c < 8192) {
$data .= @fread($fp, $c);
$c = 0;
} else {
$c -= 8192;
$data .= @fread($fp, 8192);
}
}
if ($entry[4] & self::GZ) {
$data = gzinflate($data);
} elseif ($entry[4] & self::BZ2) {
$data = bzdecompress($data);
}
if (strlen($data) != $entry[0]) {
die("Invalid internal .phar file (size error " . strlen($data) . " != " .
$stat[7] . ")");
}
if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
die("Invalid internal .phar file (checksum error)");
}
return $data;
}
static function _removeTmpFiles($temp, $origdir)
{
chdir($temp);
foreach (glob('*') as $f) {
if (file_exists($f)) {
is_dir($f) ? @rmdir($f) : @unlink($f);
if (file_exists($f) && is_dir($f)) {
self::_removeTmpFiles($f, getcwd());
}
}
}
@rmdir($temp);
clearstatcache();
chdir($origdir);
}
static $temp;
static $origdir;
const GZ = 0x1000;
const BZ2 = 0x2000;
const MASK = 0x3000;
const START = 'index.php';
const LEN = XXXX;
static function go($return = false)
{
$fp = fopen(__FILE__, 'rb');
fseek($fp, self::LEN);
$L = unpack('V', $a = (binary)fread($fp, 4));
$m = (binary)'';
do {
$read = 8192;
if ($L[1] - strlen($m) < 8192) {
$read = $L[1] - strlen($m);
}
$last = (binary)fread($fp, $read);
$m .= $last;
} while (strlen($last) && strlen($m) < $L[1]);
if (strlen($m) < $L[1]) {
die('ERROR: manifest length read was "' .
strlen($m) .'" should be "' .
$L[1] . '"');
}
$info = self::_unpack($m);
$f = $info['c'];
if ($f & self::GZ) {
if (!function_exists('gzinflate')) {
die('Error: zlib extension is not enabled -' .
' gzinflate() function needed for zlib-compressed .phars');
}
}
if ($f & self::BZ2) {
if (!function_exists('bzdecompress')) {
die('Error: bzip2 extension is not enabled -' .
' bzdecompress() function needed for bz2-compressed .phars');
}
}
$temp = self::tmpdir();
if (!$temp || !is_writable($temp)) {
$sessionpath = session_save_path();
if (strpos ($sessionpath, ";") !== false)
$sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1);
if (!file_exists($sessionpath) || !is_dir($sessionpath)) {
die('Could not locate temporary directory to extract phar');
}
$temp = $sessionpath;
}
$temp .= '/pharextract/'.basename(__FILE__, '.phar');
self::$temp = $temp;
self::$origdir = getcwd();
@mkdir($temp, 0777, true);
$temp = realpath($temp);
if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) {
self::_removeTmpFiles($temp, getcwd());
@mkdir($temp, 0777, true);
@file_put_contents($temp . '/' . md5_file(__FILE__), '');
foreach ($info['m'] as $path => $file) {
$a = !file_exists(dirname($temp . '/' . $path));
@mkdir(dirname($temp . '/' . $path), 0777, true);
clearstatcache();
if ($path[strlen($path) - 1] == '/') {
@mkdir($temp . '/' . $path, 0777);
} else {
file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp));
@chmod($temp . '/' . $path, 0666);
}
}
}
chdir($temp);
if (!$return) {
include self::START;
}
}
static function tmpdir()
{
if (strpos(PHP_OS, 'WIN') !== false) {
if ($var = getenv('TMP') ? getenv('TMP') : getenv('TEMP')) {
return $var;
}
if (is_dir('/temp') || mkdir('/temp')) {
return realpath('/temp');
}
return false;
}
if ($var = getenv('TMPDIR')) {
return $var;
}
return realpath('/tmp');
}
static function _unpack($m)
{
$info = unpack('V', substr($m, 0, 4));
// skip API version, phar flags, alias, metadata
$l = unpack('V', substr($m, 10, 4));
$m = substr($m, 14 + $l[1]);
$s = unpack('V', substr($m, 0, 4));
$o = 0;
$start = 4 + $s[1];
$ret['c'] = 0;
for ($i = 0; $i < $info[1]; $i++) {
// length of the file name
$len = unpack('V', substr($m, $start, 4));
$start += 4;
// file name
$savepath = substr($m, $start, $len[1]);
$start += $len[1];
// retrieve manifest data:
// 0 = size, 1 = timestamp, 2 = compressed size, 3 = crc32, 4 = flags
// 5 = metadata length
$ret['m'][$savepath] = array_values(unpack('Va/Vb/Vc/Vd/Ve/Vf', substr($m, $start, 24)));
$ret['m'][$savepath][3] = sprintf('%u', $ret['m'][$savepath][3]
& 0xffffffff);
$ret['m'][$savepath][7] = $o;
$o += $ret['m'][$savepath][2];
$start += 24 + $ret['m'][$savepath][5];
$ret['c'] |= $ret['m'][$savepath][4] & self::MASK;
}
return $ret;
}
static function extractFile($path, $entry, $fp)
{
$data = '';
$c = $entry[2];
while ($c) {
if ($c < 8192) {
$data .= @fread($fp, $c);
$c = 0;
} else {
$c -= 8192;
$data .= @fread($fp, 8192);
}
}
if ($entry[4] & self::GZ) {
$data = gzinflate($data);
} elseif ($entry[4] & self::BZ2) {
$data = bzdecompress($data);
}
if (strlen($data) != $entry[0]) {
die("Invalid internal .phar file (size error " . strlen($data) . " != " .
$stat[7] . ")");
}
if ($entry[3] != sprintf("%u", crc32((binary)$data) & 0xffffffff)) {
die("Invalid internal .phar file (checksum error)");
}
return $data;
}
static function _removeTmpFiles($temp, $origdir)
{
chdir($temp);
foreach (glob('*') as $f) {
if (file_exists($f)) {
is_dir($f) ? @rmdir($f) : @unlink($f);
if (file_exists($f) && is_dir($f)) {
self::_removeTmpFiles($f, getcwd());
}
}
}
@rmdir($temp);
clearstatcache();
chdir($origdir);
}
}
Loading…
Cancel
Save