|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CL\ComposerInit\Prompt; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
|
6
|
|
|
use CL\ComposerInit\GitConfig; |
|
7
|
|
|
use CL\ComposerInit\Inflector; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Helper\DialogHelper; |
|
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 TitlePrompt implements PromptInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var Client |
|
20
|
|
|
*/ |
|
21
|
|
|
private $github; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var GitConfig |
|
25
|
|
|
*/ |
|
26
|
|
|
private $gitConfig; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var Inflector |
|
30
|
|
|
*/ |
|
31
|
|
|
private $inflector; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param GitConfig $gitConfig |
|
35
|
|
|
* @param Client $github |
|
36
|
|
|
* @param Inflector $inflector |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function __construct(GitConfig $gitConfig, Client $github, Inflector $inflector) |
|
39
|
|
|
{ |
|
40
|
1 |
|
$this->gitConfig = $gitConfig; |
|
41
|
1 |
|
$this->github = $github; |
|
42
|
1 |
|
$this->inflector = $inflector; |
|
43
|
1 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return GitConfig |
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function getGitConfig() |
|
49
|
|
|
{ |
|
50
|
1 |
|
return $this->gitConfig; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return Client |
|
55
|
|
|
*/ |
|
56
|
1 |
|
public function getGithub() |
|
57
|
|
|
{ |
|
58
|
1 |
|
return $this->github; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return Inflector |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function getInflector() |
|
65
|
|
|
{ |
|
66
|
1 |
|
return $this->inflector; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
2 |
|
public function getDefault() |
|
73
|
|
|
{ |
|
74
|
2 |
|
$origin = $this->gitConfig->getOrigin(); |
|
75
|
|
|
|
|
76
|
2 |
|
if (null !== $origin) { |
|
77
|
1 |
|
$response = $this->github->get("/repos/{$origin}"); |
|
78
|
1 |
|
$repo = json_decode($response->getBody(), true); |
|
79
|
1 |
|
return $this->inflector->title($repo['name']); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
1 |
|
return $this->inflector->title(getcwd()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param OutputInterface $output |
|
87
|
|
|
* @param DialogHelper $dialog |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function getValues(OutputInterface $output, DialogHelper $dialog) |
|
91
|
|
|
{ |
|
92
|
1 |
|
$default = $this->getDefault(); |
|
93
|
|
|
|
|
94
|
1 |
|
$value = $dialog->ask( |
|
95
|
1 |
|
$output, |
|
96
|
1 |
|
"<info>Title</info> ({$default}): ", |
|
97
|
|
|
$default |
|
98
|
1 |
|
); |
|
99
|
|
|
|
|
100
|
|
|
return [ |
|
101
|
1 |
|
'title' => $value, |
|
102
|
1 |
|
'title_underline' => str_pad('', mb_strlen($value), '='), |
|
103
|
1 |
|
]; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
|