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

Source for file Action.php

Documentation is available at Action.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 an option action.
  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.     // Properties {{{
  39.  
  40.     /**
  41.      * A reference to the result instance.
  42.      *
  43.      * @var Console_CommandLine_Result $result The result instance
  44.      */
  45.     protected $result;
  46.  
  47.     /**
  48.      * A reference to the option instance.
  49.      *
  50.      * @var Console_CommandLine_Option $option The action option
  51.      */
  52.     protected $option;
  53.  
  54.     /**
  55.      * A reference to the parser instance.
  56.      *
  57.      * @var Console_CommandLine $parser The parser
  58.      */
  59.     protected $parser;
  60.  
  61.     // }}}
  62.     // __construct() {{{
  63.  
  64.     /**
  65.      * Constructor
  66.      *
  67.      * @param Console_CommandLine_Result $result The result instance
  68.      * @param Console_CommandLine_Option $option The action option
  69.      * @param Console_CommandLine        $parser The current parser
  70.      *
  71.      * @return void 
  72.      */
  73.     public function __construct($result$option$parser)
  74.     {
  75.         $this->result = $result;
  76.         $this->option = $option;
  77.         $this->parser = $parser;
  78.     }
  79.  
  80.     // }}}
  81.     // getResult() {{{
  82.  
  83.     /**
  84.      * Convenience method to retrieve the value of result->options[name].
  85.      *
  86.      * @return mixed The result value or null
  87.      */
  88.     public function getResult()
  89.     {
  90.         if (isset($this->result->options[$this->option->name])) {
  91.             return $this->result->options[$this->option->name];
  92.         }
  93.         return null;
  94.     }
  95.  
  96.     // }}}
  97.     // format() {{{
  98.  
  99.     /**
  100.      * Allow a value to be pre-formatted prior to being used in a choices test.
  101.      * Setting $value to the new format will keep the formatting.
  102.      *
  103.      * @param mixed &$value The value to format
  104.      *
  105.      * @return mixed The formatted value
  106.      */
  107.     public function format(&$value)
  108.     {
  109.         return $value;
  110.     }
  111.  
  112.     // }}}
  113.     // setResult() {{{
  114.  
  115.     /**
  116.      * Convenience method to assign the result->options[name] value.
  117.      *
  118.      * @param mixed $result The result value
  119.      *
  120.      * @return void 
  121.      */
  122.     public function setResult($result)
  123.     {
  124.         $this->result->options[$this->option->name$result;
  125.     }
  126.  
  127.     // }}}
  128.     // execute() {{{
  129.  
  130.     /**
  131.      * Executes the action with the value entered by the user.
  132.      * All children actions must implement this method.
  133.      *
  134.      * @param mixed $value  The option value
  135.      * @param array $params An optional array of parameters
  136.      *
  137.      * @return string 
  138.      */
  139.     abstract public function execute($value = false$params = array());
  140.     // }}}
  141. }

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