web/lib/Zend/Console/Getopt.php
changeset 1230 68c69c656a2c
parent 807 877f952ae2bd
equal deleted inserted replaced
1229:5a6b6e770365 1230:68c69c656a2c
    13  * obtain it through the world-wide-web, please send an email
    13  * obtain it through the world-wide-web, please send an email
    14  * to license@zend.com so we can send you a copy immediately.
    14  * to license@zend.com so we can send you a copy immediately.
    15  *
    15  *
    16  * @category   Zend
    16  * @category   Zend
    17  * @package    Zend_Console_Getopt
    17  * @package    Zend_Console_Getopt
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Getopt.php 24593 2012-01-05 20:35:02Z matthew $
    20  * @version    $Id$
    21  */
    21  */
    22 
    22 
    23 /**
    23 /**
    24  * Zend_Console_Getopt is a class to parse options for command-line
    24  * Zend_Console_Getopt is a class to parse options for command-line
    25  * applications.
    25  * applications.
    78  * Example:  'abc:' means options '-a', '-b', and '-c'
    78  * Example:  'abc:' means options '-a', '-b', and '-c'
    79  * are legal, and the latter requires a string parameter.
    79  * are legal, and the latter requires a string parameter.
    80  *
    80  *
    81  * @category   Zend
    81  * @category   Zend
    82  * @package    Zend_Console_Getopt
    82  * @package    Zend_Console_Getopt
    83  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    83  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
    84  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    84  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    85  * @version    Release: @package_version@
    85  * @version    Release: @package_version@
    86  * @since      Class available since Release 0.6.0
    86  * @since      Class available since Release 0.6.0
    87  *
    87  *
    88  * @todo  Handle params with multiple values, e.g. --colors=red,green,blue
    88  * @todo  Handle params with multiple values, e.g. --colors=red,green,blue
   730         $this->_parsed = true;
   730         $this->_parsed = true;
   731         return $this;
   731         return $this;
   732     }
   732     }
   733 
   733 
   734     /**
   734     /**
       
   735      * @throws Zend_Console_Getopt_Exception
       
   736      */
       
   737     public function checkRequiredArguments()
       
   738     {
       
   739         foreach ($this->_rules as $name => $rule) {
       
   740             if ($rule['param'] === 'required') {
       
   741                 $defined = false;
       
   742                 foreach ($rule['alias'] as $alias) {
       
   743                     $defined = $defined === true ? true : array_key_exists($alias, $this->_options);
       
   744                 }
       
   745                 if ($defined === false) {
       
   746                     require_once 'Zend/Console/Getopt/Exception.php';
       
   747                     throw new Zend_Console_Getopt_Exception(
       
   748                         'Option "$alias" requires a parameter.',
       
   749                         $this->getUsageMessage()
       
   750                     );
       
   751                 }
       
   752             }
       
   753         }
       
   754     }
       
   755 
       
   756     /**
   735      * Parse command-line arguments for a single long option.
   757      * Parse command-line arguments for a single long option.
   736      * A long option is preceded by a double '--' character.
   758      * A long option is preceded by a double '--' character.
   737      * Long options may not be clustered.
   759      * Long options may not be clustered.
   738      *
   760      *
   739      * @param  mixed &$argv
   761      * @param  mixed &$argv
   787                 $this->getUsageMessage());
   809                 $this->getUsageMessage());
   788         }
   810         }
   789         $realFlag = $this->_ruleMap[$flag];
   811         $realFlag = $this->_ruleMap[$flag];
   790         switch ($this->_rules[$realFlag]['param']) {
   812         switch ($this->_rules[$realFlag]['param']) {
   791             case 'required':
   813             case 'required':
   792                 if (count($argv) > 0) {
   814                 if (count($argv) > 0 && substr($argv[0], 0, 1) != '-') {
   793                     $param = array_shift($argv);
   815                     $param = array_shift($argv);
   794                     $this->_checkParameterType($realFlag, $param);
   816                     $this->_checkParameterType($realFlag, $param);
   795                 } else {
   817                 } else {
   796                     require_once 'Zend/Console/Getopt/Exception.php';
   818                     require_once 'Zend/Console/Getopt/Exception.php';
   797                     throw new Zend_Console_Getopt_Exception(
   819                     throw new Zend_Console_Getopt_Exception(