|
0
|
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 * Required by this class.
|
|
|
27 */
|
|
|
28 require_once 'Console/CommandLine/Action.php';
|
|
|
29
|
|
|
30 /**
|
|
|
31 * Class that represent the Callback action.
|
|
|
32 *
|
|
|
33 * The result option array entry value is set to the return value of the
|
|
|
34 * callback defined in the option.
|
|
|
35 *
|
|
|
36 * There are two steps to defining a callback option:
|
|
|
37 * - define the option itself using the callback action
|
|
|
38 * - write the callback; this is a function (or method) that takes five
|
|
|
39 * arguments, as described below.
|
|
|
40 *
|
|
|
41 * All callbacks are called as follows:
|
|
|
42 * <code>
|
|
|
43 * callable_func(
|
|
|
44 * $value, // the value of the option
|
|
|
45 * $option_instance, // the option instance
|
|
|
46 * $result_instance, // the result instance
|
|
|
47 * $parser_instance, // the parser instance
|
|
|
48 * $params // an array of params as specified in the option
|
|
|
49 * );
|
|
|
50 * </code>
|
|
|
51 * and *must* return the option value.
|
|
|
52 *
|
|
|
53 * @category Console
|
|
|
54 * @package Console_CommandLine
|
|
|
55 * @author David JEAN LOUIS <izimobil@gmail.com>
|
|
|
56 * @copyright 2007 David JEAN LOUIS
|
|
|
57 * @license http://opensource.org/licenses/mit-license.php MIT License
|
|
|
58 * @version Release: @package_version@
|
|
|
59 * @link http://pear.php.net/package/Console_CommandLine
|
|
|
60 * @since Class available since release 0.1.0
|
|
|
61 */
|
|
|
62 class Console_CommandLine_Action_Callback extends Console_CommandLine_Action
|
|
|
63 {
|
|
|
64 // execute() {{{
|
|
|
65
|
|
|
66 /**
|
|
|
67 * Executes the action with the value entered by the user.
|
|
|
68 *
|
|
|
69 * @param mixed $value The value of the option
|
|
|
70 * @param array $params An optional array of parameters
|
|
|
71 *
|
|
|
72 * @return string
|
|
|
73 */
|
|
|
74 public function execute($value = false, $params = array())
|
|
|
75 {
|
|
|
76 $this->setResult(call_user_func($this->option->callback, $value,
|
|
|
77 $this->option, $this->result, $this->parser, $params));
|
|
|
78 }
|
|
|
79 // }}}
|
|
|
80 }
|