@@ -23,6 +23,13 @@ class NewCommand extends Command
23
23
24
24
protected static $ defaultName = 'new ' ;
25
25
26
+ protected static $ availableContainers = [
27
+ 'Social Authentication ' => 'apiato/social-auth-container ' ,
28
+ 'Localization ' => 'apiato/localization-container ' ,
29
+ 'Payments ' => 'apiato/payment-container ' ,
30
+ 'Settings ' => 'apiato/settings-container ' ,
31
+ ];
32
+
26
33
protected function configure ()
27
34
{
28
35
$ this
@@ -38,6 +45,13 @@ protected function configure()
38
45
protected function execute (InputInterface $ input , OutputInterface $ output )
39
46
{
40
47
48
+ // Init
49
+ $ helper = $ this ->getHelper ('question ' );
50
+ $ name = $ input ->getArgument ('name ' );
51
+ $ directory = $ name !== '. ' ? getcwd () . '/ ' . $ name : '. ' ;
52
+ $ version = $ this ->getVersion ($ input );
53
+ $ composer = $ this ->findComposer ();
54
+
41
55
$ output ->writeln ([
42
56
'<fg=red> ' . PHP_EOL . PHP_EOL . PHP_EOL ,
43
57
" ___ .______ __ ___ .___________. ______ " ,
@@ -51,11 +65,32 @@ protected function execute(InputInterface $input, OutputInterface $output)
51
65
52
66
sleep (1 );
53
67
54
- $ name = $ input -> getArgument ( ' name ' );
68
+ // Ask for configurations
55
69
56
- $ directory = $ name !== '. ' ? getcwd () . '/ ' . $ name : '. ' ;
70
+ $ confirmation = new ConfirmationQuestion ('Do you want to add additional containers? (yes/no) [no] ' , false );
71
+ $ installContainersCommand = null ;
57
72
58
- $ version = $ this ->getVersion ($ input );
73
+ if ($ helper ->ask ($ input , $ output , $ confirmation )) {
74
+ $ question = new ChoiceQuestion (
75
+ 'Select all containers you want to install (example: 2,3,4). ' ,
76
+ array_keys (self ::$ availableContainers )
77
+ );
78
+
79
+ $ question ->setMultiselect (true );
80
+
81
+ $ selectedContainersArray = $ helper ->ask ($ input , $ output , $ question );
82
+ $ selectedContainersString = "" ;
83
+ $ installContainersCommand = ['cd ' . $ directory ];
84
+
85
+ foreach (array_keys (self ::$ availableContainers ) as $ availableContainer ) {
86
+ if (in_array ($ availableContainer , $ selectedContainersArray )) {
87
+ $ selectedContainersString .= ' ' . self ::$ availableContainers [$ availableContainer ];
88
+ }
89
+ }
90
+ array_push ($ installContainersCommand , $ composer . " require " . $ selectedContainersString );
91
+ }
92
+
93
+ // Start installing project
59
94
60
95
if (!$ input ->getOption ('force ' )) {
61
96
$ this ->verifyApplicationDoesntExist ($ directory );
@@ -65,8 +100,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
65
100
throw new RuntimeException ('Cannot use --force option when using current directory for installation! ' );
66
101
}
67
102
68
- $ composer = $ this ->findComposer ();
69
-
70
103
$ commands = [
71
104
$ composer . " create-project apiato/apiato \"$ directory \" $ version --remove-vcs --prefer-dist " ,
72
105
];
@@ -91,39 +124,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
91
124
}
92
125
}
93
126
94
- $ helper = $ this ->getHelper ('question ' );
95
-
96
- $ confirmation = new ConfirmationQuestion ('Now do you want to add additional containers? [default: no] ' , false );
97
-
98
- $ availableContainers = [
99
- 'Social Authentication ' => 'apiato/social-auth-container ' ,
100
- 'Localization ' => 'apiato/localization-container ' ,
101
- 'Payments ' => 'apiato/payment-container ' ,
102
- 'Settings ' => 'apiato/settings-container ' ,
103
- ];
104
-
105
- if ($ helper ->ask ($ input , $ output , $ confirmation )) {
106
- $ question = new ChoiceQuestion (
107
- 'Select all containers you want to install (example: 2,3,4). ' ,
108
- array_keys ($ availableContainers )
109
- );
110
-
111
- $ question ->setMultiselect (true );
112
-
113
- $ selectedContainersArray = $ helper ->ask ($ input , $ output , $ question );
114
- $ selectedContainersString = "" ;
115
- $ commands = ['cd ' . $ directory ];
116
-
117
- foreach (array_keys ($ availableContainers ) as $ availableContainer ) {
118
- if (in_array ($ availableContainer , $ selectedContainersArray )) {
119
- $ selectedContainersString .= ' ' . $ availableContainers [$ availableContainer ];
120
- }
121
- }
122
-
123
- array_push ($ commands , $ composer . " require " . $ selectedContainersString );
124
- $ this ->runCommands ($ commands , $ input , $ output );
125
- }
127
+ // Install additional containers
128
+ if ($ installContainersCommand ) $ this ->runCommands ($ installContainersCommand , $ input , $ output );
126
129
130
+ // The End
127
131
$ output ->writeln (PHP_EOL . '<comment>Apiato ready! Build something amazing.</comment> ' );
128
132
129
133
return $ process ->getExitCode ();
0 commit comments