1
|
|
|
<?php |
2
|
|
|
namespace Consolidation\AnnotatedCommand; |
3
|
|
|
|
4
|
|
|
use Consolidation\AnnotatedCommand\Hooks\Dispatchers\ReplaceCommandHookDispatcher; |
5
|
|
|
use Psr\Log\LoggerAwareInterface; |
6
|
|
|
use Psr\Log\LoggerAwareTrait; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\ConsoleOutputInterface; |
10
|
|
|
|
11
|
|
|
use Consolidation\OutputFormatters\FormatterManager; |
12
|
|
|
use Consolidation\OutputFormatters\Options\FormatterOptions; |
13
|
|
|
use Consolidation\AnnotatedCommand\Hooks\HookManager; |
14
|
|
|
use Consolidation\AnnotatedCommand\Options\PrepareFormatter; |
15
|
|
|
|
16
|
|
|
use Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher; |
17
|
|
|
use Consolidation\AnnotatedCommand\Hooks\Dispatchers\OptionsHookDispatcher; |
18
|
|
|
use Consolidation\AnnotatedCommand\Hooks\Dispatchers\InteractHookDispatcher; |
19
|
|
|
use Consolidation\AnnotatedCommand\Hooks\Dispatchers\ValidateHookDispatcher; |
20
|
|
|
use Consolidation\AnnotatedCommand\Hooks\Dispatchers\ProcessResultHookDispatcher; |
21
|
|
|
use Consolidation\AnnotatedCommand\Hooks\Dispatchers\StatusDeterminerHookDispatcher; |
22
|
|
|
use Consolidation\AnnotatedCommand\Hooks\Dispatchers\ExtracterHookDispatcher; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Prepare parameter list for execurion. Handle injection of any |
26
|
|
|
* special values (e.g. $input and $output) into the parameter list. |
27
|
|
|
*/ |
28
|
|
|
class ParameterInjection |
29
|
|
|
{ |
30
|
|
|
public function args($commandData) |
31
|
|
|
{ |
32
|
|
|
return array_merge( |
33
|
|
|
$commandData->injectedInstances(), |
34
|
|
|
$commandData->getArgsAndOptions() |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function injectIntoCommandData($commandData, $injectedClasses) |
39
|
|
|
{ |
40
|
|
|
foreach ($injectedClasses as $injectedClass) { |
41
|
|
|
$injectedInstance = $this->getInstanceToInject($commandData, $injectedClass); |
42
|
|
|
$commandData->injectInstance($injectedInstance); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function getInstanceToInject(CommandData $commandData, $injectedClass) |
47
|
|
|
{ |
48
|
|
|
switch ($injectedClass) { |
49
|
|
|
case 'Symfony\Component\Console\Input\InputInterface': |
50
|
|
|
return $commandData->input(); |
51
|
|
|
case 'Symfony\Component\Console\Output\OutputInterface': |
52
|
|
|
return $commandData->output(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return null; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|