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 Version action.
|
|
32 *
|
|
33 * The execute methode add 1 to the value of the result option array entry.
|
|
34 * The value is incremented each time the option is found, for example
|
|
35 * with an option defined like that:
|
|
36 *
|
|
37 * <code>
|
|
38 * $parser->addOption(
|
|
39 * 'verbose',
|
|
40 * array(
|
|
41 * 'short_name' => '-v',
|
|
42 * 'action' => 'Counter'
|
|
43 * )
|
|
44 * );
|
|
45 * </code>
|
|
46 * If the user type:
|
|
47 * <code>
|
|
48 * $ script.php -v -v -v
|
|
49 * </code>
|
|
50 * or:
|
|
51 * <code>
|
|
52 * $ script.php -vvv
|
|
53 * </code>
|
|
54 * the verbose variable will be set to to 3.
|
|
55 *
|
|
56 * @category Console
|
|
57 * @package Console_CommandLine
|
|
58 * @author David JEAN LOUIS <izimobil@gmail.com>
|
|
59 * @copyright 2007 David JEAN LOUIS
|
|
60 * @license http://opensource.org/licenses/mit-license.php MIT License
|
|
61 * @version Release: @package_version@
|
|
62 * @link http://pear.php.net/package/Console_CommandLine
|
|
63 * @since Class available since release 0.1.0
|
|
64 */
|
|
65 class Console_CommandLine_Action_Counter extends Console_CommandLine_Action
|
|
66 {
|
|
67 // execute() {{{
|
|
68
|
|
69 /**
|
|
70 * Executes the action with the value entered by the user.
|
|
71 *
|
|
72 * @param mixed $value The option value
|
|
73 * @param array $params An optional array of parameters
|
|
74 *
|
|
75 * @return string
|
|
76 */
|
|
77 public function execute($value = false, $params = array())
|
|
78 {
|
|
79 $result = $this->getResult();
|
|
80 if ($result === null) {
|
|
81 $result = 0;
|
|
82 }
|
|
83 $this->setResult(++$result);
|
|
84 }
|
|
85 // }}}
|
|
86 }
|