comparison vendor/pear/console_commandline/Console/CommandLine/Action.php @ 0:1e000243b222

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:50:29 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e000243b222
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: @package_version@
34 * @link http://pear.php.net/package/Console_CommandLine
35 * @since Class available since release 0.1.0
36 */
37 abstract class Console_CommandLine_Action
38 {
39 // Properties {{{
40
41 /**
42 * A reference to the result instance.
43 *
44 * @var Console_CommandLine_Result $result The result instance
45 */
46 protected $result;
47
48 /**
49 * A reference to the option instance.
50 *
51 * @var Console_CommandLine_Option $option The action option
52 */
53 protected $option;
54
55 /**
56 * A reference to the parser instance.
57 *
58 * @var Console_CommandLine $parser The parser
59 */
60 protected $parser;
61
62 // }}}
63 // __construct() {{{
64
65 /**
66 * Constructor
67 *
68 * @param Console_CommandLine_Result $result The result instance
69 * @param Console_CommandLine_Option $option The action option
70 * @param Console_CommandLine $parser The current parser
71 *
72 * @return void
73 */
74 public function __construct($result, $option, $parser)
75 {
76 $this->result = $result;
77 $this->option = $option;
78 $this->parser = $parser;
79 }
80
81 // }}}
82 // getResult() {{{
83
84 /**
85 * Convenience method to retrieve the value of result->options[name].
86 *
87 * @return mixed The result value or null
88 */
89 public function getResult()
90 {
91 if (isset($this->result->options[$this->option->name])) {
92 return $this->result->options[$this->option->name];
93 }
94 return null;
95 }
96
97 // }}}
98 // format() {{{
99
100 /**
101 * Allow a value to be pre-formatted prior to being used in a choices test.
102 * Setting $value to the new format will keep the formatting.
103 *
104 * @param mixed &$value The value to format
105 *
106 * @return mixed The formatted value
107 */
108 public function format(&$value)
109 {
110 return $value;
111 }
112
113 // }}}
114 // setResult() {{{
115
116 /**
117 * Convenience method to assign the result->options[name] value.
118 *
119 * @param mixed $result The result value
120 *
121 * @return void
122 */
123 public function setResult($result)
124 {
125 $this->result->options[$this->option->name] = $result;
126 }
127
128 // }}}
129 // execute() {{{
130
131 /**
132 * Executes the action with the value entered by the user.
133 * All children actions must implement this method.
134 *
135 * @param mixed $value The option value
136 * @param array $params An optional array of parameters
137 *
138 * @return string
139 */
140 abstract public function execute($value = false, $params = array());
141 // }}}
142 }