From: Marcus Boerger Date: Thu, 10 May 2007 21:49:40 +0000 (+0000) Subject: - Update phar command X-Git-Tag: RELEASE_1_2_0~111 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0283cfad77e7f62615c463e5f6dec52a6d75c8cf;p=php - Update phar command --- 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