]> granicus.if.org Git - php/commitdiff
- Update phar command
authorMarcus Boerger <helly@php.net>
Thu, 10 May 2007 21:49:40 +0000 (21:49 +0000)
committerMarcus Boerger <helly@php.net>
Thu, 10 May 2007 21:49:40 +0000 (21:49 +0000)
ext/phar/phar.php
ext/phar/phar/clicommand.inc
ext/phar/phar/phar.php
ext/phar/phar/pharcommand.inc

index 0acdbce95decbd06c97cd9783e8c2317fa389c13..426439e3ae7b2e6ff8dc1278fa13a5b62008859e 100644 (file)
@@ -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)
                {
index cd0e292a514cd1f2723b8b5417f68733b50f61b4..f07fcd234f9396305639209a416c732de92a8d57 100755 (executable)
@@ -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)
index 5df884d072a6cec374ee4917b44e06caf812d895..f918032b44cfc746c8d84486d87bcafab7d3b47c 100755 (executable)
@@ -1,3 +1,4 @@
+#!/usr/bin/php
 <?php
 
 /** @file phar.php
index 5539d620b91146038dda3cd03a7d98fd00e94807..f08bbe4756b49a1de17b09bad20d198fff1d4361 100755 (executable)
@@ -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)
                {