2
2
3
3
namespace Apiato \Installer \Commands ;
4
4
5
+ use Apiato \Installer \Traits \CommandTrait ;
6
+ use Apiato \Installer \Traits \FileTrait ;
7
+ use Apiato \Installer \Traits \GitTrait ;
5
8
use RuntimeException ;
6
9
use Symfony \Component \Console \Command \Command ;
7
10
use Symfony \Component \Console \Input \InputArgument ;
8
11
use Symfony \Component \Console \Input \InputInterface ;
9
12
use Symfony \Component \Console \Input \InputOption ;
10
13
use Symfony \Component \Console \Output \OutputInterface ;
11
- use Symfony \Component \Process \Process ;
14
+ use Symfony \Component \Console \Question \ChoiceQuestion ;
15
+ use Symfony \Component \Console \Question \ConfirmationQuestion ;
12
16
13
17
class NewCommand extends Command
14
18
{
15
19
20
+ use GitTrait;
21
+ use CommandTrait;
22
+ use FileTrait;
23
+
16
24
protected static $ defaultName = 'new ' ;
17
25
18
26
protected function configure ()
@@ -88,134 +96,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
88
96
return $ process ->getExitCode ();
89
97
}
90
98
91
- /**
92
- * Get the version that should be downloaded.
93
- *
94
- * @param \Symfony\Component\Console\Input\InputInterface $input
95
- * @return string
96
- */
97
- protected function getVersion (InputInterface $ input )
98
- {
99
- if ($ input ->getOption ('dev ' )) {
100
- return 'dev-master ' ;
101
- }
102
-
103
- return '' ;
104
- }
105
-
106
- /**
107
- * Create a Git repository and commit the base Apiato skeleton.
108
- *
109
- * @param string $directory
110
- * @param \Symfony\Component\Console\Input\InputInterface $input
111
- * @param \Symfony\Component\Console\Output\OutputInterface $output
112
- * @return void
113
- */
114
- protected function createRepository (string $ directory , InputInterface $ input , OutputInterface $ output )
115
- {
116
- chdir ($ directory );
117
-
118
- $ branch = $ input ->getOption ('branch ' ) ?: 'main ' ;
119
-
120
- $ commands = [
121
- "git init -q -b {$ branch } . " ,
122
- 'git add . ' ,
123
- 'git commit -q -m "Set up a fresh Apiato app" ' ,
124
- ];
125
-
126
- $ this ->runCommands ($ commands , $ input , $ output );
127
- }
128
-
129
- /**
130
- * Verify that the application does not already exist.
131
- *
132
- * @param string $directory
133
- * @return void
134
- */
135
- protected function verifyApplicationDoesntExist ($ directory )
136
- {
137
- if ((is_dir ($ directory ) || is_file ($ directory )) && $ directory != getcwd ()) {
138
- throw new RuntimeException ('Application already exists! ' );
139
- }
140
- }
141
-
142
- /**
143
- * Get the composer command for the environment.
144
- *
145
- * @return string
146
- */
147
- protected function findComposer ()
148
- {
149
- $ composerPath = getcwd () . '/composer.phar ' ;
150
-
151
- if (file_exists ($ composerPath )) {
152
- return '" ' . PHP_BINARY . '" ' . $ composerPath ;
153
- }
154
-
155
- return 'composer ' ;
156
- }
157
-
158
- /**
159
- * Run the given commands.
160
- *
161
- * @param array $commands
162
- * @param \Symfony\Component\Console\Input\InputInterface $input
163
- * @param \Symfony\Component\Console\Output\OutputInterface $output
164
- * @param array $env
165
- * @return \Symfony\Component\Process\Process
166
- */
167
- protected function runCommands ($ commands , InputInterface $ input , OutputInterface $ output , array $ env = [])
168
- {
169
- if ($ input ->getOption ('no-ansi ' )) {
170
- $ commands = array_map (function ($ value ) {
171
- if (substr ($ value , 0 , 5 ) === 'chmod ' ) {
172
- return $ value ;
173
- }
174
-
175
- return $ value . ' --no-ansi ' ;
176
- }, $ commands );
177
- }
178
-
179
- if ($ input ->getOption ('quiet ' )) {
180
- $ commands = array_map (function ($ value ) {
181
- if (substr ($ value , 0 , 5 ) === 'chmod ' ) {
182
- return $ value ;
183
- }
184
-
185
- return $ value . ' --quiet ' ;
186
- }, $ commands );
187
- }
188
-
189
- $ process = Process::fromShellCommandline (implode (' && ' , $ commands ), null , $ env , null , null );
190
-
191
- if ('\\' !== DIRECTORY_SEPARATOR && file_exists ('/dev/tty ' ) && is_readable ('/dev/tty ' )) {
192
- try {
193
- $ process ->setTty (true );
194
- } catch (RuntimeException $ e ) {
195
- $ output ->writeln ('Warning: ' . $ e ->getMessage ());
196
- }
197
- }
198
-
199
- $ process ->run (function ($ type , $ line ) use ($ output ) {
200
- $ output ->write (' ' . $ line );
201
- });
202
-
203
- return $ process ;
204
- }
205
-
206
- /**
207
- * Replace the given string in the given file.
208
- *
209
- * @param string $search
210
- * @param string $replace
211
- * @param string $file
212
- * @return void
213
- */
214
- protected function replaceInFile (string $ search , string $ replace , string $ file )
215
- {
216
- file_put_contents (
217
- $ file ,
218
- str_replace ($ search , $ replace , file_get_contents ($ file ))
219
- );
220
- }
221
- }
99
+ }
0 commit comments