|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CRM library |
|
4
|
|
|
* @author Tao <[email protected]> |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace Slince\Crm\Command; |
|
7
|
|
|
|
|
8
|
|
|
use Slince\Crm\Registry; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Question\ChoiceQuestion; |
|
13
|
|
|
|
|
14
|
|
|
class UseCommand extends Command |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Command name |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
const NAME = 'use'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
public function configure() |
|
26
|
|
|
{ |
|
27
|
|
|
parent::configure(); |
|
28
|
|
|
$this->setName(static::NAME) |
|
29
|
|
|
->setDescription('Change current registry') |
|
30
|
|
|
->addArgument('registry-name', InputArgument::OPTIONAL, 'The registry name you want use'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
public function execute(InputInterface $input, OutputInterface $output) |
|
37
|
|
|
{ |
|
38
|
|
|
$registryName = $input->getArgument('registry-name'); |
|
39
|
|
|
//auto select |
|
40
|
|
|
if (is_null($registryName)) { |
|
41
|
|
|
$helper = $this->getHelper('question'); |
|
42
|
|
|
$question = new ChoiceQuestion( |
|
43
|
|
|
'Please select your favorite registry (defaults to composer)', |
|
44
|
|
|
array_map(function (Registry $registry) { |
|
45
|
|
|
return $registry->getName(); |
|
46
|
|
|
}, $this->getManager()->getRegistries()->all()), |
|
47
|
|
|
0 |
|
48
|
|
|
); |
|
49
|
|
|
$question->setErrorMessage('Registry %s is invalid.'); |
|
50
|
|
|
$registryName = $helper->ask($input, $output, $question); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$registry = $this->getManager()->findRegistry($registryName); |
|
54
|
|
|
$this->getManager()->useRegistry($registry, $this->checkIsCurrent($input)); |
|
55
|
|
|
|
|
56
|
|
|
$output->writeln("<info>Use registry [{$registryName}] success</info>"); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|