Chris@13
|
1 <?php
|
Chris@13
|
2
|
Chris@13
|
3 /*
|
Chris@13
|
4 * This file is part of Psy Shell.
|
Chris@13
|
5 *
|
Chris@13
|
6 * (c) 2012-2018 Justin Hileman
|
Chris@13
|
7 *
|
Chris@13
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@13
|
9 * file that was distributed with this source code.
|
Chris@13
|
10 */
|
Chris@13
|
11
|
Chris@13
|
12 namespace Psy\Input;
|
Chris@13
|
13
|
Chris@13
|
14 use Symfony\Component\Console\Input\InputArgument;
|
Chris@13
|
15
|
Chris@13
|
16 /**
|
Chris@13
|
17 * An input argument for code.
|
Chris@13
|
18 *
|
Chris@13
|
19 * A CodeArgument must be the final argument of the command. Once all options
|
Chris@13
|
20 * and other arguments are used, any remaining input until the end of the string
|
Chris@13
|
21 * is considered part of a single CodeArgument, regardless of spaces, quoting,
|
Chris@13
|
22 * escaping, etc.
|
Chris@13
|
23 *
|
Chris@13
|
24 * This means commands can support crazy input like
|
Chris@13
|
25 *
|
Chris@13
|
26 * parse function() { return "wheee\n"; }
|
Chris@13
|
27 *
|
Chris@13
|
28 * ... without having to put the code in a quoted string and escape everything.
|
Chris@13
|
29 */
|
Chris@13
|
30 class CodeArgument extends InputArgument
|
Chris@13
|
31 {
|
Chris@13
|
32 /**
|
Chris@13
|
33 * Constructor.
|
Chris@13
|
34 *
|
Chris@13
|
35 * @param string $name The argument name
|
Chris@13
|
36 * @param int $mode The argument mode: self::REQUIRED or self::OPTIONAL
|
Chris@13
|
37 * @param string $description A description text
|
Chris@13
|
38 * @param mixed $default The default value (for self::OPTIONAL mode only)
|
Chris@13
|
39 *
|
Chris@13
|
40 * @throws \InvalidArgumentException When argument mode is not valid
|
Chris@13
|
41 */
|
Chris@13
|
42 public function __construct($name, $mode = null, $description = '', $default = null)
|
Chris@13
|
43 {
|
Chris@13
|
44 if ($mode & InputArgument::IS_ARRAY) {
|
Chris@13
|
45 throw new \InvalidArgumentException('Argument mode IS_ARRAY is not valid');
|
Chris@13
|
46 }
|
Chris@13
|
47
|
Chris@13
|
48 parent::__construct($name, $mode, $description, $default);
|
Chris@13
|
49 }
|
Chris@13
|
50 }
|