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

Source for file Element.php

Documentation is available at Element.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.  * Class that represent a command line element (an option, or an argument).
  27.  *
  28.  * @category  Console
  29.  * @package   Console_CommandLine
  30.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  31.  * @copyright 2007 David JEAN LOUIS
  32.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  33.  * @version   Release: 1.2.0
  34.  * @link      http://pear.php.net/package/Console_CommandLine
  35.  * @since     Class available since release 0.1.0
  36.  */
  37. {
  38.     // Public properties {{{
  39.  
  40.     /**
  41.      * The element name.
  42.      *
  43.      * @var string $name Element name
  44.      */
  45.     public $name;
  46.  
  47.     /**
  48.      * The name of variable displayed in the usage message, if no set it
  49.      * defaults to the "name" property.
  50.      *
  51.      * @var string $help_name Element "help" variable name
  52.      */
  53.     public $help_name;
  54.  
  55.     /**
  56.      * The element description.
  57.      *
  58.      * @var string $description Element description
  59.      */
  60.     public $description;
  61.  
  62.     /**
  63.      * The default value of the element if not provided on the command line.
  64.      *
  65.      * @var mixed $default Default value of the option.
  66.      */
  67.     public $default;
  68.  
  69.     /**
  70.      * Custom errors messages for this element
  71.      *
  72.      * This array is of the form:
  73.      * <code>
  74.      * <?php
  75.      * array(
  76.      *     $messageName => $messageText,
  77.      *     $messageName => $messageText,
  78.      *     ...
  79.      * );
  80.      * ?>
  81.      * </code>
  82.      *
  83.      * If specified, these messages override the messages provided by the
  84.      * default message provider. For example:
  85.      * <code>
  86.      * <?php
  87.      * $messages = array(
  88.      *     'ARGUMENT_REQUIRED' => 'The argument foo is required.',
  89.      * );
  90.      * ?>
  91.      * </code>
  92.      *
  93.      * @var array 
  94.      * @see Console_CommandLine_MessageProvider_Default
  95.      */
  96.     public $messages = array();
  97.  
  98.     // }}}
  99.     // __construct() {{{
  100.  
  101.     /**
  102.      * Constructor.
  103.      *
  104.      * @param string $name   The name of the element
  105.      * @param array  $params An optional array of parameters
  106.      *
  107.      * @return void 
  108.      */
  109.     public function __construct($name = null$params = array()) 
  110.     {
  111.         $this->name = $name;
  112.         foreach ($params as $attr => $value{
  113.             if (property_exists($this$attr)) {
  114.                 $this->$attr $value;
  115.             }
  116.         }
  117.     }
  118.  
  119.     // }}}
  120.     // toString() {{{
  121.  
  122.     /**
  123.      * Returns the string representation of the element.
  124.      *
  125.      * @return string The string representation of the element
  126.      * @todo use __toString() instead
  127.      */
  128.     public function toString()
  129.     {
  130.         return $this->help_name;
  131.     }
  132.     // }}}
  133.     // validate() {{{
  134.  
  135.     /**
  136.      * Validates the element instance and set it's default values.
  137.      *
  138.      * @return void 
  139.      * @throws Console_CommandLine_Exception
  140.      */
  141.     public function validate()
  142.     {
  143.         // if no help_name passed, default to name
  144.         if ($this->help_name == null{
  145.             $this->help_name = $this->name;
  146.         }
  147.     }
  148.  
  149.     // }}}
  150. }

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