1 | <?php |
||
18 | class InitCommand extends LlumCommand |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Github api service class. |
||
23 | * |
||
24 | * @var GithubAPI |
||
25 | */ |
||
26 | protected $api; |
||
27 | |||
28 | /** |
||
29 | * Filesystem. |
||
30 | * |
||
31 | * @var Filesystem |
||
32 | */ |
||
33 | protected $filesystem; |
||
34 | |||
35 | /** |
||
36 | * Compiler for llumrc file. |
||
37 | * |
||
38 | * @var RCFileCompiler |
||
39 | */ |
||
40 | protected $compiler; |
||
41 | |||
42 | /** |
||
43 | * Command name. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $commandName = 'init'; |
||
48 | |||
49 | /** |
||
50 | * Command description. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $commandDescription = 'Create ~/.llumrc file with llum configuration data'; |
||
55 | |||
56 | /** |
||
57 | * Method to execute. |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $method = 'init'; |
||
62 | |||
63 | /** |
||
64 | * Github username |
||
65 | * |
||
66 | * @var |
||
67 | */ |
||
68 | protected $github_username; |
||
69 | |||
70 | /** |
||
71 | * Github token. |
||
72 | * |
||
73 | * @var string |
||
74 | */ |
||
75 | protected $github_token = ""; |
||
76 | |||
77 | /** |
||
78 | * Get path to stub. |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | protected function getStubPath() { |
||
85 | |||
86 | |||
87 | /** |
||
88 | * InitCommand constructor. |
||
89 | * |
||
90 | * @param Filesystem $filesystem |
||
91 | * @param RCFileCompiler $compiler |
||
92 | * @param GithubAPI $api |
||
93 | */ |
||
94 | public function __construct(Filesystem $filesystem, RCFileCompiler $compiler, GithubAPI $api) |
||
101 | |||
102 | /** |
||
103 | * init command. |
||
104 | */ |
||
105 | public function init(InputInterface $input, OutputInterface $output) |
||
106 | { |
||
107 | try { |
||
108 | $this->executeWizard($input,$output); |
||
109 | $this->filesystem->overwrite( |
||
110 | (new LlumRCFile())->path(), |
||
111 | $this->compiler->compile( |
||
112 | $this->filesystem->get($this->getStubPath()), |
||
113 | $this->data)); |
||
|
|||
114 | } catch (\Exception $e) { |
||
115 | print_r($e->xdebug_message); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Executes wizard. |
||
121 | * |
||
122 | * @param InputInterface $input |
||
123 | * @param OutputInterface $output |
||
124 | */ |
||
125 | protected function executeWizard(InputInterface $input, OutputInterface $output){ |
||
136 | |||
137 | /** |
||
138 | * @param InputInterface $input |
||
139 | * @param OutputInterface $output |
||
140 | */ |
||
141 | public function askGithubUsername(InputInterface $input, OutputInterface $output) |
||
147 | |||
148 | /** |
||
149 | * @return string |
||
150 | */ |
||
151 | protected function defaultUsername() |
||
155 | |||
156 | /** |
||
157 | * @param InputInterface $input |
||
158 | * @param OutputInterface $output |
||
159 | */ |
||
160 | public function askGithubToken(InputInterface $input, OutputInterface $output) |
||
169 | |||
170 | /** |
||
171 | * @param InputInterface $input |
||
172 | * @param OutputInterface $output |
||
173 | * @return mixed |
||
174 | */ |
||
175 | protected function askGithubPassword(InputInterface $input, OutputInterface $output) { |
||
182 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: