2 namespace Consolidation\AnnotatedCommand;
4 use Symfony\Component\Console\Input\InputInterface;
5 use Symfony\Component\Console\Output\OutputInterface;
9 /** var AnnotationData */
10 protected $annotationData;
11 /** var InputInterface */
13 /** var OutputInterface */
16 protected $usesInputInterface;
18 protected $usesOutputInterface;
20 protected $includeOptionsInArgs;
22 public function __construct(
23 AnnotationData $annotationData,
24 InputInterface $input,
25 OutputInterface $output,
26 $usesInputInterface = false,
27 $usesOutputInterface = false
29 $this->annotationData = $annotationData;
30 $this->input = $input;
31 $this->output = $output;
32 $this->usesInputInterface = false;
33 $this->usesOutputInterface = false;
34 $this->includeOptionsInArgs = true;
38 * For internal use only; indicates that the function to be called
39 * should be passed an InputInterface &/or an OutputInterface.
40 * @param booean $usesInputInterface
41 * @param boolean $usesOutputInterface
44 public function setUseIOInterfaces($usesInputInterface, $usesOutputInterface)
46 $this->usesInputInterface = $usesInputInterface;
47 $this->usesOutputInterface = $usesOutputInterface;
52 * For backwards-compatibility mode only: disable addition of
53 * options on the end of the arguments list.
55 public function setIncludeOptionsInArgs($includeOptionsInArgs)
57 $this->includeOptionsInArgs = $includeOptionsInArgs;
61 public function annotationData()
63 return $this->annotationData;
66 public function input()
71 public function output()
76 public function arguments()
78 return $this->input->getArguments();
81 public function options()
83 return $this->input->getOptions();
86 public function getArgsWithoutAppName()
88 $args = $this->arguments();
90 // When called via the Application, the first argument
91 // will be the command name. The Application alters the
92 // input definition to match, adding a 'command' argument
96 if ($this->usesInputInterface) {
97 array_unshift($args, $this->input());
100 if ($this->usesOutputInterface) {
101 array_unshift($args, $this->output());
107 public function getArgsAndOptions()
109 // Get passthrough args, and add the options on the end.
110 $args = $this->getArgsWithoutAppName();
111 if ($this->includeOptionsInArgs) {
112 $args['options'] = $this->options();