1 | <?php |
||
20 | class AnnotatedCommandFactory implements AutomaticOptionsProviderInterface |
||
21 | { |
||
22 | /** var CommandProcessor */ |
||
23 | protected $commandProcessor; |
||
24 | |||
25 | /** var CommandCreationListenerInterface[] */ |
||
26 | protected $listeners = []; |
||
27 | |||
28 | /** var AutomaticOptionsProvider[] */ |
||
29 | |||
30 | protected $automaticOptionsProviderList = []; |
||
31 | |||
32 | /** var boolean */ |
||
33 | protected $includeAllPublicMethods = true; |
||
34 | |||
35 | public function __construct() |
||
40 | |||
41 | public function setCommandProcessor(CommandProcessor $commandProcessor) |
||
45 | |||
46 | /** |
||
47 | * @return CommandProcessor |
||
48 | */ |
||
49 | public function commandProcessor() |
||
53 | |||
54 | /** |
||
55 | * Set the 'include all public methods flag'. If true (the default), then |
||
56 | * every public method of each commandFile will be used to create commands. |
||
57 | * If it is false, then only those public methods annotated with @command |
||
58 | * or @name (deprecated) will be used to create commands. |
||
59 | */ |
||
60 | public function setIncludeAllPublicMethods($includeAllPublicMethods) |
||
64 | |||
65 | public function getIncludeAllPublicMethods() |
||
69 | |||
70 | /** |
||
71 | * @return HookManager |
||
72 | */ |
||
73 | public function hookManager() |
||
77 | |||
78 | /** |
||
79 | * Add a listener that is notified immediately before the command |
||
80 | * factory creates commands from a commandFile instance. This |
||
81 | * listener can use this opportunity to do more setup for the commandFile, |
||
82 | * and so on. |
||
83 | * |
||
84 | * @param CommandCreationListenerInterface $listener |
||
85 | */ |
||
86 | public function addListener(CommandCreationListenerInterface $listener) |
||
90 | |||
91 | /** |
||
92 | * Call all command creation listeners |
||
93 | * |
||
94 | * @param object $commandFileInstance |
||
95 | */ |
||
96 | protected function notify($commandFileInstance) |
||
102 | |||
103 | public function addAutomaticOptionProvider(AutomaticOptionsProviderInterface $optionsProvider) |
||
107 | |||
108 | public function createCommandsFromClass($commandFileInstance, $includeAllPublicMethods = null) |
||
119 | |||
120 | public function getCommandInfoListFromClass($classNameOrInstance) |
||
140 | |||
141 | public function createCommandInfo($classNameOrInstance, $commandMethodName) |
||
145 | |||
146 | public function createCommandsFromClassInfo($commandInfoList, $commandFileInstance, $includeAllPublicMethods = null) |
||
160 | |||
161 | public function createSelectedCommandsFromClassInfo($commandInfoList, $commandFileInstance, callable $commandSelector) |
||
174 | |||
175 | public static function isCommandMethod($commandInfo) |
||
182 | |||
183 | public function registerCommandHooksFromClassInfo($commandInfoList, $commandFileInstance) |
||
191 | |||
192 | /** |
||
193 | * Register a command hook given the CommandInfo for a method. |
||
194 | * |
||
195 | * The hook format is: |
||
196 | * |
||
197 | * @hook type name type |
||
198 | * |
||
199 | * For example, the pre-validate hook for the core:init command is: |
||
200 | * |
||
201 | * @hook pre-validate core:init |
||
202 | * |
||
203 | * If no command name is provided, then this hook will affect every |
||
204 | * command that is defined in the same file. |
||
205 | * |
||
206 | * If no hook is provided, then we will presume that ALTER_RESULT |
||
207 | * is intended. |
||
208 | * |
||
209 | * @param CommandInfo $commandInfo Information about the command hook method. |
||
210 | * @param object $commandFileInstance An instance of the CommandFile class. |
||
211 | */ |
||
212 | public function registerCommandHook(CommandInfo $commandInfo, $commandFileInstance) |
||
226 | |||
227 | protected function getNthWord($string, $n, $default = '', $delimiter = ' ') |
||
235 | |||
236 | public function createCommand(CommandInfo $commandInfo, $commandFileInstance) |
||
251 | |||
252 | /** |
||
253 | * Get the options that are implied by annotations, e.g. @fields implies |
||
254 | * that there should be a --fields and a --format option. |
||
255 | * |
||
256 | * @return InputOption[] |
||
257 | */ |
||
258 | public function callAutomaticOptionsProviders(CommandInfo $commandInfo) |
||
266 | |||
267 | /** |
||
268 | * Get the options that are implied by annotations, e.g. @fields implies |
||
269 | * that there should be a --fields and a --format option. |
||
270 | * |
||
271 | * @return InputOption[] |
||
272 | */ |
||
273 | public function automaticOptions(CommandInfo $commandInfo) |
||
285 | } |
||
286 |