4 namespace Stecman\Component\Symfony\Console\BashCompletion;
6 use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionInterface;
8 class Completion implements CompletionInterface
11 * The type of input (option/argument) the completion should be run for
13 * @see CompletionInterface::ALL_TYPES
19 * The command name the completion should be run for
21 * @see CompletionInterface::ALL_COMMANDS
24 protected $commandName;
27 * The option/argument name the completion should be run for
31 protected $targetName;
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.
39 protected $completion;
42 * Create a Completion with the command name set to CompletionInterface::ALL_COMMANDS
44 * @deprecated - This will be removed in 1.0.0 as it is redundant and isn't any more concise than what it implements.
46 * @param string $targetName
48 * @param array|callable $completion
51 public static function makeGlobalHandler($targetName, $type, $completion)
53 return new Completion(CompletionInterface::ALL_COMMANDS, $targetName, $type, $completion);
57 * @param string $commandName
58 * @param string $targetName
60 * @param array|callable $completion
62 public function __construct($commandName, $targetName, $type, $completion)
64 $this->commandName = $commandName;
65 $this->targetName = $targetName;
67 $this->completion = $completion;
71 * Return the stored completion, or the results returned from the completion callback
77 if ($this->isCallable()) {
78 return call_user_func($this->completion);
81 return $this->completion;
85 * Get type of input (option/argument) the completion should be run for
87 * @see CompletionInterface::ALL_TYPES
90 public function getType()
96 * Set type of input (option/argument) the completion should be run for
98 * @see CompletionInterface::ALL_TYPES
99 * @param string|null $type
101 public function setType($type)
107 * Get the command name the completion should be run for
109 * @see CompletionInterface::ALL_COMMANDS
110 * @return string|null
112 public function getCommandName()
114 return $this->commandName;
118 * Set the command name the completion should be run for
120 * @see CompletionInterface::ALL_COMMANDS
121 * @param string|null $commandName
123 public function setCommandName($commandName)
125 $this->commandName = $commandName;
129 * Set the option/argument name the completion should be run for
134 public function getTargetName()
136 return $this->targetName;
140 * Get the option/argument name the completion should be run for
143 * @param string $targetName
145 public function setTargetName($targetName)
147 $this->targetName = $targetName;
151 * Return the array or callback configured for for the Completion
153 * @return array|callable
155 public function getCompletion()
157 return $this->completion;
161 * Set the array or callback to return/run when Completion is run
164 * @param array|callable $completion
166 public function setCompletion($completion)
168 $this->completion = $completion;
172 * Check if the configured completion value is a callback function
176 public function isCallable()
178 return is_callable($this->completion);