summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2007-05-10 21:49:40 +0000
committerMarcus Boerger <helly@php.net>2007-05-10 21:49:40 +0000
commit0283cfad77e7f62615c463e5f6dec52a6d75c8cf (patch)
tree6665b4194e6dde99bfd47c5e9bf804ffd51b8c5a
parent5779f46bfdefe39bfc309a954e4ad2a10beebd77 (diff)
downloadphp-git-0283cfad77e7f62615c463e5f6dec52a6d75c8cf.tar.gz
- Update phar command
-rw-r--r--ext/phar/phar.php48
-rwxr-xr-xext/phar/phar/clicommand.inc18
-rwxr-xr-xext/phar/phar/phar.php1
-rwxr-xr-xext/phar/phar/pharcommand.inc31
4 files changed, 80 insertions, 18 deletions
diff --git a/ext/phar/phar.php b/ext/phar/phar.php
index 0acdbce95d..426439e3ae 100644
--- a/ext/phar/phar.php
+++ b/ext/phar/phar.php
@@ -232,14 +232,27 @@ if (!class_exists('CLICommand'))
static function cli_arg_typ_file($arg)
{
- if (!file_exists($arg))
+ $f = realpath($arg);
+ if ($f===false || !file_exists($f))
{
echo "Requested file '$arg' does not exist.\n";
exit(1);
}
- return $arg;
+ return $f;
}
+ static function cli_arg_typ_filenew($arg)
+ {
+ $d = dirname($arg);
+ $f = realpath($d);
+ if ($f === false)
+ {
+ echo "Path for file '$arg' does not exist.\n";
+ exit(1);
+ }
+ return $f . substr($arg, strlen($d));;
+ }
+
static function cli_arg_typ_filecont($arg)
{
return file_get_contents(self::cli_arg_typ_file($arg));
@@ -322,20 +335,37 @@ class PharCommand extends CLICommand
return str_repeat(' ', $l1 + 2 + 17);
}
+ static function strEndsWith($haystack, $needle)
+ {
+ return substr($haystack, -strlen($needle)) == $needle;
+ }
+
+ static function cli_arg_typ_pharnew($arg)
+ {
+ $pharfile = self::cli_arg_typ_filenew($arg);
+ if (!self::strEndsWith($pharfile, '.phar')
+ && !self::strEndsWith($pharfile, '.phar.php')
+ && !self::strEndsWith($pharfile, '.phar.bz2')
+ && !self::strEndsWith($pharfile, '.phar.gz')
+ )
+ {
+ echo "Phar files must have file extension '.pahr', '.parh.php', '.phar.bz2' or 'phar.gz'.\n";
+ exit(1);
+ }
+ return $pharfile;
+ }
+
static function cli_arg_typ_pharfile($arg)
{
try
{
- if (!file_exists($arg) && file_exists($ps = dirname(__FILE__).'/'.$arg))
- {
- $arg = $ps;
- }
- if (!Phar::loadPhar($arg))
+ $pharfile = self::cli_arg_typ_file($arg);
+ if (!Phar::loadPhar($pharfile))
{
- "Unable to open phar '$phar'\n";
+ "Unable to open phar '$arg'\n";
exit(1);
}
- return $arg;
+ return $pharfile;
}
catch(Exception $e)
{
diff --git a/ext/phar/phar/clicommand.inc b/ext/phar/phar/clicommand.inc
index cd0e292a51..f07fcd234f 100755
--- a/ext/phar/phar/clicommand.inc
+++ b/ext/phar/phar/clicommand.inc
@@ -181,12 +181,26 @@ abstract class CLICommand
static function cli_arg_typ_file($arg)
{
- if (!file_exists($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 $arg;
+ return $f;
+ }
+
+ static function cli_arg_typ_filenew($arg)
+ {
+ $d = dirname($arg);
+ $f = realpath($d);
+ if ($f === false)
+ {
+ echo "Path for file '$arg' does not exist.\n";
+ exit(1);
+ }
+ return $f . substr($arg, strlen($d));;
}
static function cli_arg_typ_filecont($arg)
diff --git a/ext/phar/phar/phar.php b/ext/phar/phar/phar.php
index 5df884d072..f918032b44 100755
--- a/ext/phar/phar/phar.php
+++ b/ext/phar/phar/phar.php
@@ -1,3 +1,4 @@
+#!/usr/bin/php
<?php
/** @file phar.php
diff --git a/ext/phar/phar/pharcommand.inc b/ext/phar/phar/pharcommand.inc
index 5539d620b9..f08bbe4756 100755
--- a/ext/phar/phar/pharcommand.inc
+++ b/ext/phar/phar/pharcommand.inc
@@ -21,20 +21,37 @@ class PharCommand extends CLICommand
return str_repeat(' ', $l1 + 2 + 17);
}
+ static function strEndsWith($haystack, $needle)
+ {
+ return substr($haystack, -strlen($needle)) == $needle;
+ }
+
+ static function cli_arg_typ_pharnew($arg)
+ {
+ $pharfile = self::cli_arg_typ_filenew($arg);
+ if (!self::strEndsWith($pharfile, '.phar')
+ && !self::strEndsWith($pharfile, '.phar.php')
+ && !self::strEndsWith($pharfile, '.phar.bz2')
+ && !self::strEndsWith($pharfile, '.phar.gz')
+ )
+ {
+ echo "Phar files must have file extension '.pahr', '.parh.php', '.phar.bz2' or 'phar.gz'.\n";
+ exit(1);
+ }
+ return $pharfile;
+ }
+
static function cli_arg_typ_pharfile($arg)
{
try
{
- if (!file_exists($arg) && file_exists($ps = dirname(__FILE__).'/'.$arg))
- {
- $arg = $ps;
- }
- if (!Phar::loadPhar($arg))
+ $pharfile = self::cli_arg_typ_file($arg);
+ if (!Phar::loadPhar($pharfile))
{
- "Unable to open phar '$phar'\n";
+ "Unable to open phar '$arg'\n";
exit(1);
}
- return $arg;
+ return $pharfile;
}
catch(Exception $e)
{