1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverLeague\Console\Command; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Config\Collections\ConfigCollectionInterface; |
6
|
|
|
use SilverStripe\Core\Config\Config; |
7
|
|
|
use SilverStripe\Core\Injector\Injector; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Console\Question\Question; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A slightly embellished Symfony Command class which is SilverStripe aware |
15
|
|
|
* |
16
|
|
|
* @package silverstripe-console |
17
|
|
|
* @author Robbie Averill <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class SilverStripeCommand extends Command |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Retrieve an argument from the input interface, or use the Question helper to ask for input |
23
|
|
|
* if it wasn't provided. Will automatically hide input for password fields. |
24
|
|
|
* |
25
|
|
|
* @param InputInterface $input |
26
|
|
|
* @param OutputInterface $output |
27
|
|
|
* @param string $key The argument key, e.g. "username" |
28
|
|
|
* @param string $question The question to ask, e.g. "Which username: " |
29
|
|
|
* @return string|null |
30
|
3 |
|
*/ |
31
|
|
|
protected function getOrAskForArgument(InputInterface $input, OutputInterface $output, $key, $question) |
32
|
3 |
|
{ |
33
|
3 |
|
if ($supplied = $input->getArgument($key)) { |
|
|
|
|
34
|
|
|
return $supplied; |
35
|
|
|
} |
36
|
1 |
|
|
37
|
1 |
|
$question = new Question($question); |
38
|
1 |
|
if (stripos($key, 'password') !== false) { |
39
|
1 |
|
$question->setHidden(true); |
40
|
|
|
$question->setHiddenFallback(false); |
41
|
|
|
} |
42
|
1 |
|
|
43
|
|
|
return $this->getHelper('question')->ask($input, $output, $question); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get the SilverStripe Injector |
48
|
|
|
* |
49
|
|
|
* @return Injector |
50
|
1 |
|
*/ |
51
|
|
|
public function getInjector() |
52
|
1 |
|
{ |
53
|
|
|
return Injector::inst(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the configuration API handler |
58
|
|
|
* |
59
|
|
|
* @return ConfigCollectionInterface |
60
|
1 |
|
*/ |
61
|
|
|
public function getConfig() |
62
|
1 |
|
{ |
63
|
|
|
return Config::inst(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|