|
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 StoreArray action.
|
|
|
32 *
|
|
|
33 * The execute method appends the value of the option entered by the user to
|
|
|
34 * the result option array entry.
|
|
|
35 *
|
|
|
36 * @category Console
|
|
|
37 * @package Console_CommandLine
|
|
|
38 * @author David JEAN LOUIS <izimobil@gmail.com>
|
|
|
39 * @copyright 2007 David JEAN LOUIS
|
|
|
40 * @license http://opensource.org/licenses/mit-license.php MIT License
|
|
|
41 * @version Release: @package_version@
|
|
|
42 * @link http://pear.php.net/package/Console_CommandLine
|
|
|
43 * @since Class available since release 0.1.0
|
|
|
44 */
|
|
|
45 class Console_CommandLine_Action_StoreArray extends Console_CommandLine_Action
|
|
|
46 {
|
|
|
47 // Protected properties {{{
|
|
|
48
|
|
|
49 /**
|
|
|
50 * Force a clean result when first called, overriding any defaults assigned.
|
|
|
51 *
|
|
|
52 * @var object $firstPass First time this action has been called.
|
|
|
53 */
|
|
|
54 protected $firstPass = true;
|
|
|
55
|
|
|
56 // }}}
|
|
|
57 // execute() {{{
|
|
|
58
|
|
|
59 /**
|
|
|
60 * Executes the action with the value entered by the user.
|
|
|
61 *
|
|
|
62 * @param mixed $value The option value
|
|
|
63 * @param array $params An optional array of parameters
|
|
|
64 *
|
|
|
65 * @return string
|
|
|
66 */
|
|
|
67 public function execute($value = false, $params = array())
|
|
|
68 {
|
|
|
69 $result = $this->getResult();
|
|
|
70 if (null === $result || $this->firstPass) {
|
|
|
71 $result = array();
|
|
|
72 $this->firstPass = false;
|
|
|
73 }
|
|
|
74 $result[] = $value;
|
|
|
75 $this->setResult($result);
|
|
|
76 }
|
|
|
77 // }}}
|
|
|
78 }
|