Console_CommandLine
[ class tree: Console_CommandLine ] [ index: Console_CommandLine ] [ all elements ]

Source for file Argument.php

Documentation is available at Argument.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * This file is part of the PEAR Console_CommandLine package.
  7.  *
  8.  * PHP version 5
  9.  *
  10.  * LICENSE: This source file is subject to the MIT license that is available
  11.  * through the world-wide-web at the following URI:
  12.  * http://opensource.org/licenses/mit-license.php
  13.  *
  14.  * @category  Console
  15.  * @package   Console_CommandLine
  16.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  17.  * @copyright 2007 David JEAN LOUIS
  18.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  19.  * @version   CVS: $Id$
  20.  * @link      http://pear.php.net/package/Console_CommandLine
  21.  * @since     File available since release 0.1.0
  22.  * @filesource
  23.  */
  24.  
  25. /**
  26.  * Include base element class.
  27.  */
  28. require_once 'Console/CommandLine/Element.php';
  29.  
  30. /**
  31.  * Class that represent a command line argument.
  32.  *
  33.  * @category  Console
  34.  * @package   Console_CommandLine
  35.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  36.  * @copyright 2007 David JEAN LOUIS
  37.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  38.  * @version   Release: 1.2.0
  39.  * @link      http://pear.php.net/package/Console_CommandLine
  40.  * @since     Class available since release 0.1.0
  41.  */
  42. {
  43.     // Public properties {{{
  44.  
  45.     /**
  46.      * Setting this to true will tell the parser that the argument expects more
  47.      * than one argument and that argument values should be stored in an array.
  48.      *
  49.      * @var boolean $multiple Whether the argument expects multiple values
  50.      */
  51.     public $multiple = false;
  52.  
  53.     /**
  54.      * Setting this to true will tell the parser that the argument is optional
  55.      * and can be ommited.
  56.      * Note that it is not a good practice to make arguments optional, it is
  57.      * the role of the options to be optional, by essence.
  58.      *
  59.      * @var boolean $optional Whether the argument is optional or not.
  60.      */
  61.     public $optional = false;
  62.  
  63.     /**
  64.      * An array of possible values for the argument.
  65.      *
  66.      * @var array $choices Valid choices for the argument
  67.      */
  68.     public $choices = array();
  69.  
  70.     // }}}
  71.     // validate() {{{
  72.  
  73.     /**
  74.      * Validates the argument instance.
  75.      *
  76.      * @return void 
  77.      * @throws Console_CommandLine_Exception
  78.      * @todo use exceptions
  79.      */
  80.     public function validate()
  81.     {
  82.         // check if the argument name is valid
  83.         if (!preg_match('/^[a-zA-Z_\x7f-\xff]+[a-zA-Z0-9_\x7f-\xff]*$/',
  84.             $this->name)) {
  85.             Console_CommandLine::triggerError(
  86.                 'argument_bad_name',
  87.                 E_USER_ERROR,
  88.                 array('{$name}' => $this->name)
  89.             );
  90.         }
  91.         if (!$this->optional && $this->default !== null{
  92.             Console_CommandLine::triggerError(
  93.                 'argument_no_default',
  94.                 E_USER_ERROR
  95.             );
  96.         }
  97.         parent::validate();
  98.     }
  99.  
  100.     // }}}
  101. }

Documentation generated on Mon, 11 Mar 2019 15:51:31 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.