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: Element.php 282427 2009-06-19 10:22:48Z izi $
  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.1.3
  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.      * Custom errors messages for this element
  64.      *
  65.      * This array is of the form:
  66.      * <code>
  67.      * <?php
  68.      * array(
  69.      *     $messageName => $messageText,
  70.      *     $messageName => $messageText,
  71.      *     ...
  72.      * );
  73.      * ?>
  74.      * </code>
  75.      *
  76.      * If specified, these messages override the messages provided by the
  77.      * default message provider. For example:
  78.      * <code>
  79.      * <?php
  80.      * $messages = array(
  81.      *     'ARGUMENT_REQUIRED' => 'The argument foo is required.',
  82.      * );
  83.      * ?>
  84.      * </code>
  85.      *
  86.      * @var array 
  87.      * @see Console_CommandLine_MessageProvider_Default
  88.      */
  89.     public $messages = array();
  90.  
  91.     // }}}
  92.     // __construct() {{{
  93.  
  94.     /**
  95.      * Constructor.
  96.      *
  97.      * @param string $name   The name of the element
  98.      * @param array  $params An optional array of parameters
  99.      *
  100.      * @return void 
  101.      */
  102.     public function __construct($name = null$params = array()) 
  103.     {
  104.         $this->name = $name;
  105.         foreach ($params as $attr => $value{
  106.             if (property_exists($this$attr)) {
  107.                 $this->$attr $value;
  108.             }
  109.         }
  110.     }
  111.  
  112.     // }}}
  113.     // toString() {{{
  114.  
  115.     /**
  116.      * Returns the string representation of the element.
  117.      *
  118.      * @return string The string representation of the element
  119.      * @todo use __toString() instead
  120.      */
  121.     public function toString()
  122.     {
  123.         return $this->help_name;
  124.     }
  125.     // }}}
  126.     // validate() {{{
  127.  
  128.     /**
  129.      * Validates the element instance and set it's default values.
  130.      *
  131.      * @return void 
  132.      * @throws Console_CommandLine_Exception
  133.      */
  134.     public function validate()
  135.     {
  136.         // if no help_name passed, default to name
  137.         if ($this->help_name == null{
  138.             $this->help_name = $this->name;
  139.         }
  140.     }
  141.  
  142.     // }}}
  143. }

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