Procházet zdrojové kódy

ZF-6610
- Supplied fix for allowing processing for unknown arguments (originally commited by wil to incubator for Zend_Build development)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15528 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph před 16 roky
rodič
revize
f15f7e8a91
1 změnil soubory, kde provedl 16 přidání a 5 odebrání
  1. 16 5
      library/Zend/Console/Getopt.php

+ 16 - 5
library/Zend/Console/Getopt.php

@@ -126,6 +126,7 @@
  */
 class Zend_Console_Getopt
 {
+
     /**
      * The options for a given application can be in multiple formats.
      * modeGnu is for traditional 'ab:c:' style getopt format.
@@ -149,23 +150,26 @@ class Zend_Console_Getopt
      * ruleMode is either 'zend' or 'gnu' or a user-defined mode.
      * dashDash is true if '--' signifies the end of command-line options.
      * ignoreCase is true if '--opt' and '--OPT' are implicitly synonyms.
+     * parseAll is true if all options on the command line should be parsed, regardless of
+     * whether an argument appears before them.
      */
     const CONFIG_RULEMODE                   = 'ruleMode';
     const CONFIG_DASHDASH                   = 'dashDash';
     const CONFIG_IGNORECASE                 = 'ignoreCase';
+    const CONFIG_PARSEALL                   = 'parseAll';
 
     /**
      * Defaults for getopt configuration are:
      * ruleMode is 'zend' format,
      * dashDash (--) token is enabled,
-     * ignoreCase is not enabled.
-     *
-     * @var array Config
+     * ignoreCase is not enabled,
+     * parseAll is enabled.
      */
     protected $_getoptConfig = array(
         self::CONFIG_RULEMODE   => self::MODE_ZEND,
         self::CONFIG_DASHDASH   => true,
-        self::CONFIG_IGNORECASE => false
+        self::CONFIG_IGNORECASE => false,
+        self::CONFIG_PARSEALL => true
     );
 
     /**
@@ -699,8 +703,15 @@ class Zend_Console_Getopt
                 $this->_parseLongOption($argv);
             } else if (substr($argv[0], 0, 1) == '-' && ('-' != $argv[0] || count($argv) >1))  {
                 $this->_parseShortOptionCluster($argv);
-            } else {
+            } else if($this->_getoptConfig[self::CONFIG_PARSEALL]) {
                 $this->_remainingArgs[] = array_shift($argv);
+            } else {
+                /*
+                 * We should put all other arguments in _remainingArgs and stop parsing
+                 * since CONFIG_PARSEALL is false.
+                 */
+                $this->_remainingArgs = array_merge($this->_remainingArgs, $argv);
+                break;
             }
         }
         $this->_parsed = true;