1 | <?php |
||
31 | class ArgsFormatInputDefinition extends InputDefinition |
||
32 | { |
||
33 | /** |
||
34 | * @var CommandName[] |
||
35 | */ |
||
36 | private $commandNames = array(); |
||
37 | |||
38 | /** |
||
39 | * Creates a new adapter. |
||
40 | * |
||
41 | * @param ArgsFormat $format The adapted format. |
||
42 | */ |
||
43 | 322 | public function __construct(ArgsFormat $format) |
|
44 | { |
||
45 | 322 | parent::__construct(); |
|
46 | |||
47 | 322 | $i = 1; |
|
48 | |||
49 | 322 | foreach ($format->getCommandNames() as $commandName) { |
|
50 | do { |
||
51 | 308 | $argName = 'cmd'.$i++; |
|
52 | 308 | } while ($format->hasArgument($argName)); |
|
53 | |||
54 | 308 | $this->addArgument($argument = $this->adaptCommandName($commandName, $argName)); |
|
55 | |||
56 | 308 | $this->commandNames[$argument->getName()] = $commandName; |
|
57 | } |
||
58 | |||
59 | 322 | foreach ($format->getCommandOptions() as $commandOption) { |
|
60 | 87 | $this->addOption($this->adaptCommandOption($commandOption)); |
|
61 | } |
||
62 | |||
63 | 322 | foreach ($format->getOptions() as $option) { |
|
64 | 272 | $this->addOption($this->adaptOption($option)); |
|
65 | } |
||
66 | |||
67 | 322 | foreach ($format->getArguments() as $argument) { |
|
68 | 269 | $this->addArgument($this->adaptArgument($argument)); |
|
69 | } |
||
70 | 322 | } |
|
71 | |||
72 | /** |
||
73 | * Returns the command names indexed by their argument names. |
||
74 | * |
||
75 | * @return CommandName[] The command names. |
||
76 | */ |
||
77 | 297 | public function getCommandNamesByArgumentName() |
|
81 | |||
82 | /** |
||
83 | * Creates an input argument for the given command name. |
||
84 | * |
||
85 | * @param CommandName $commandName The command name. |
||
86 | * @param string $argName The name of the added argument. |
||
87 | * |
||
88 | * @return InputArgument The created input argument. |
||
89 | */ |
||
90 | 308 | private function adaptCommandName(CommandName $commandName, $argName) |
|
94 | |||
95 | /** |
||
96 | * Creates an input option for the given command option. |
||
97 | * |
||
98 | * @param CommandOption $commandOption The command option. |
||
99 | * |
||
100 | * @return InputOption The created input option. |
||
101 | */ |
||
102 | 87 | private function adaptCommandOption(CommandOption $commandOption) |
|
106 | |||
107 | /** |
||
108 | * Creates an input option for the given option. |
||
109 | * |
||
110 | * @param Option $option The option. |
||
111 | * |
||
112 | * @return InputOption The created input option. |
||
113 | */ |
||
114 | 272 | private function adaptOption(Option $option) |
|
132 | |||
133 | /** |
||
134 | * Creates an input argument for the given argument. |
||
135 | * |
||
136 | * @param Argument $argument The argument. |
||
137 | * |
||
138 | * @return InputArgument The created input argument. |
||
139 | */ |
||
140 | 269 | private function adaptArgument(Argument $argument) |
|
158 | } |
||
159 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.