1 | <?php |
||
8 | class Completion implements CompletionInterface |
||
9 | { |
||
10 | /** |
||
11 | * The type of input (option/argument) the completion should be run for |
||
12 | * |
||
13 | * @see CompletionInterface::ALL_TYPES |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $type; |
||
17 | |||
18 | /** |
||
19 | * The command name the completion should be run for |
||
20 | * |
||
21 | * @see CompletionInterface::ALL_COMMANDS |
||
22 | * @var string|null |
||
23 | */ |
||
24 | protected $commandName; |
||
25 | |||
26 | /** |
||
27 | * The option/argument name the completion should be run for |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $targetName; |
||
32 | |||
33 | /** |
||
34 | * Array of values to return, or a callback to generate completion results with |
||
35 | * The callback can be in any form accepted by call_user_func. |
||
36 | * |
||
37 | * @var callable|array |
||
38 | */ |
||
39 | protected $completion; |
||
40 | |||
41 | /** |
||
42 | * Create a Completion with the command name set to CompletionInterface::ALL_COMMANDS |
||
43 | * |
||
44 | * @deprecated - This will be removed in 1.0.0 as it is redundant and isn't any more concise than what it implements. |
||
45 | * |
||
46 | * @param string $targetName |
||
47 | * @param string $type |
||
48 | * @param array|callable $completion |
||
49 | * @return Completion |
||
50 | */ |
||
51 | public static function makeGlobalHandler($targetName, $type, $completion) |
||
55 | |||
56 | /** |
||
57 | * @param string $commandName |
||
58 | * @param string $targetName |
||
59 | * @param string $type |
||
60 | * @param array|callable $completion |
||
61 | */ |
||
62 | public function __construct($commandName, $targetName, $type, $completion) |
||
69 | |||
70 | /** |
||
71 | * Return the stored completion, or the results returned from the completion callback |
||
72 | * |
||
73 | * @return array |
||
74 | */ |
||
75 | public function run() |
||
83 | |||
84 | /** |
||
85 | * Get type of input (option/argument) the completion should be run for |
||
86 | * |
||
87 | * @see CompletionInterface::ALL_TYPES |
||
88 | * @return string|null |
||
89 | */ |
||
90 | public function getType() |
||
94 | |||
95 | /** |
||
96 | * Set type of input (option/argument) the completion should be run for |
||
97 | * |
||
98 | * @see CompletionInterface::ALL_TYPES |
||
99 | * @param string|null $type |
||
100 | */ |
||
101 | public function setType($type) |
||
105 | |||
106 | /** |
||
107 | * Get the command name the completion should be run for |
||
108 | * |
||
109 | * @see CompletionInterface::ALL_COMMANDS |
||
110 | * @return string|null |
||
111 | */ |
||
112 | public function getCommandName() |
||
116 | |||
117 | /** |
||
118 | * Set the command name the completion should be run for |
||
119 | * |
||
120 | * @see CompletionInterface::ALL_COMMANDS |
||
121 | * @param string|null $commandName |
||
122 | */ |
||
123 | public function setCommandName($commandName) |
||
127 | |||
128 | /** |
||
129 | * Set the option/argument name the completion should be run for |
||
130 | * |
||
131 | * @see setType() |
||
132 | * @return string |
||
133 | */ |
||
134 | public function getTargetName() |
||
138 | |||
139 | /** |
||
140 | * Get the option/argument name the completion should be run for |
||
141 | * |
||
142 | * @see getType() |
||
143 | * @param string $targetName |
||
144 | */ |
||
145 | public function setTargetName($targetName) |
||
149 | |||
150 | /** |
||
151 | * Return the array or callback configured for for the Completion |
||
152 | * |
||
153 | * @return array|callable |
||
154 | */ |
||
155 | public function getCompletion() |
||
159 | |||
160 | /** |
||
161 | * Set the array or callback to return/run when Completion is run |
||
162 | * |
||
163 | * @see run() |
||
164 | * @param array|callable $completion |
||
165 | */ |
||
166 | public function setCompletion($completion) |
||
170 | |||
171 | /** |
||
172 | * Check if the configured completion value is a callback function |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | public function isCallable() |
||
180 | } |
||
181 |