|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CL\ComposerInit\Prompt; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
6
|
|
|
use Symfony\Component\Console\Helper\DialogHelper; |
|
7
|
|
|
use GuzzleHttp\Client; |
|
8
|
|
|
use CL\ComposerInit\GitConfig; |
|
9
|
|
|
use CL\ComposerInit\Inflector; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Ivan Kerin <[email protected]> |
|
13
|
|
|
* @copyright (c) 2014 Clippings Ltd. |
|
14
|
|
|
* @license http://spdx.org/licenses/BSD-3-Clause |
|
15
|
|
|
*/ |
|
16
|
|
|
class Prompts |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var PromptInterface[] |
|
20
|
|
|
*/ |
|
21
|
|
|
private $prompts; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var Client |
|
25
|
|
|
*/ |
|
26
|
|
|
private $github; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var GitConfig |
|
30
|
|
|
*/ |
|
31
|
|
|
private $gitConfig; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var Inflector |
|
35
|
|
|
*/ |
|
36
|
|
|
private $inflector; |
|
37
|
|
|
|
|
38
|
1 |
|
public function __construct(GitConfig $gitConfig, Client $github, Inflector $inflector) |
|
39
|
|
|
{ |
|
40
|
1 |
|
$this->github = $github; |
|
41
|
1 |
|
$this->gitConfig = $gitConfig; |
|
42
|
1 |
|
$this->inflector = $inflector; |
|
43
|
|
|
|
|
44
|
1 |
|
$this->add('author_email', new AuthorEmailPrompt($this->gitConfig)); |
|
45
|
1 |
|
$this->add('author_name', new AuthorNamePrompt($this->gitConfig)); |
|
46
|
1 |
|
$this->add('bugs', new BugsPrompt($this->gitConfig, $this->github)); |
|
47
|
1 |
|
$this->add('copyright', new CopyrightPrompt($this->gitConfig, $this->github)); |
|
48
|
1 |
|
$this->add('description', new DescriptionPrompt($this->gitConfig, $this->github)); |
|
49
|
1 |
|
$this->add('php_namespace', new PhpNamespacePrompt($this->gitConfig, $this->inflector)); |
|
50
|
1 |
|
$this->add('package_name', new PackageNamePrompt($this->gitConfig)); |
|
51
|
1 |
|
$this->add('slack_notification', new SlackNotificationPrompt()); |
|
52
|
1 |
|
$this->add('title', new TitlePrompt($this->gitConfig, $this->github, $this->inflector)); |
|
53
|
1 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return Client |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function getGithub() |
|
59
|
|
|
{ |
|
60
|
1 |
|
return $this->github; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return GitConfig |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function getGitConfig() |
|
67
|
|
|
{ |
|
68
|
1 |
|
return $this->gitConfig; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return Inflector |
|
73
|
|
|
*/ |
|
74
|
1 |
|
public function getInflector() |
|
75
|
|
|
{ |
|
76
|
1 |
|
return $this->inflector; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return Container |
|
81
|
|
|
*/ |
|
82
|
1 |
|
public function get($name) |
|
83
|
|
|
{ |
|
84
|
1 |
|
return $this->prompts[$name]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
public function add($name, PromptInterface $prompt) |
|
88
|
|
|
{ |
|
89
|
1 |
|
$this->prompts[$name] = $prompt; |
|
90
|
1 |
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param array $prompts |
|
94
|
|
|
* @param OutputInterface $output |
|
95
|
|
|
* @param DialogHelper $dialog |
|
96
|
|
|
* @return array |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function getValues(array $prompts, OutputInterface $output, DialogHelper $dialog) |
|
99
|
|
|
{ |
|
100
|
1 |
|
$values = []; |
|
101
|
|
|
|
|
102
|
1 |
|
foreach ($prompts as $name) { |
|
103
|
1 |
|
$container = $this->get($name); |
|
104
|
|
|
|
|
105
|
1 |
|
$values = array_merge( |
|
106
|
1 |
|
$values, |
|
107
|
1 |
|
$container->getValues($output, $dialog) |
|
108
|
1 |
|
); |
|
109
|
1 |
|
} |
|
110
|
|
|
|
|
111
|
1 |
|
return $values; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
|