3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \MagentoCloud \Command \Docker ;
7
9
8
10
use Magento \MagentoCloud \Config \Environment ;
11
+ use Magento \MagentoCloud \Config \RepositoryFactory ;
9
12
use Magento \MagentoCloud \Docker \BuilderFactory ;
10
13
use Magento \MagentoCloud \Docker \BuilderInterface ;
11
14
use Magento \MagentoCloud \Docker \ConfigurationMismatchException ;
12
15
use Magento \MagentoCloud \Filesystem \Driver \File ;
13
- use Magento \MagentoCloud \Filesystem \FileList ;
14
16
use Magento \MagentoCloud \Filesystem \FileSystemException ;
15
17
use Symfony \Component \Console \Command \Command ;
16
18
use Symfony \Component \Console \Input \InputInterface ;
@@ -31,8 +33,6 @@ class Build extends Command
31
33
const OPTION_ES = 'es ' ;
32
34
const OPTION_RABBIT_MQ = 'rmq ' ;
33
35
34
- const OPTION_IS_TEST = 'test ' ;
35
-
36
36
/**
37
37
* @var BuilderFactory
38
38
*/
@@ -44,31 +44,31 @@ class Build extends Command
44
44
private $ file ;
45
45
46
46
/**
47
- * @var FileList
47
+ * @var Environment
48
48
*/
49
- private $ fileList ;
49
+ private $ environment ;
50
50
51
51
/**
52
- * @var Environment
52
+ * @var RepositoryFactory
53
53
*/
54
- private $ environment ;
54
+ private $ configFactory ;
55
55
56
56
/**
57
57
* @param BuilderFactory $builderFactory
58
58
* @param File $file
59
- * @param FileList $fileList
60
59
* @param Environment $environment
60
+ * @param RepositoryFactory $configFactory
61
61
*/
62
62
public function __construct (
63
63
BuilderFactory $ builderFactory ,
64
64
File $ file ,
65
- FileList $ fileList ,
66
- Environment $ environment
65
+ Environment $ environment ,
66
+ RepositoryFactory $ configFactory
67
67
) {
68
68
$ this ->builderFactory = $ builderFactory ;
69
69
$ this ->file = $ file ;
70
- $ this ->fileList = $ fileList ;
71
70
$ this ->environment = $ environment ;
71
+ $ this ->configFactory = $ configFactory ;
72
72
73
73
parent ::__construct ();
74
74
}
@@ -84,47 +84,34 @@ protected function configure()
84
84
self ::OPTION_PHP ,
85
85
null ,
86
86
InputOption::VALUE_OPTIONAL ,
87
- 'PHP version ' ,
88
- BuilderInterface::DEFAULT_PHP_VERSION
87
+ 'PHP version '
89
88
)->addOption (
90
89
self ::OPTION_NGINX ,
91
90
null ,
92
91
InputOption::VALUE_OPTIONAL ,
93
- 'Nginx version ' ,
94
- BuilderInterface::DEFAULT_NGINX_VERSION
92
+ 'Nginx version '
95
93
)->addOption (
96
94
self ::OPTION_DB ,
97
95
null ,
98
96
InputOption::VALUE_OPTIONAL ,
99
- 'DB version ' ,
100
- BuilderInterface::DEFAULT_DB_VERSION
97
+ 'DB version '
101
98
)->addOption (
102
99
self ::OPTION_REDIS ,
103
100
null ,
104
101
InputOption::VALUE_OPTIONAL ,
105
- 'Redis version ' ,
106
- BuilderInterface::DEFAULT_REDIS_VERSION
102
+ 'Redis version '
107
103
)->addOption (
108
104
self ::OPTION_ES ,
109
105
null ,
110
106
InputOption::VALUE_OPTIONAL ,
111
- 'ElasticSearch version ' ,
112
- BuilderInterface::DEFAULT_ES_VERSION
107
+ 'Elasticsearch version '
113
108
)->addOption (
114
109
self ::OPTION_RABBIT_MQ ,
115
110
null ,
116
111
InputOption::VALUE_OPTIONAL ,
117
- 'RabbitMQ version ' ,
118
- BuilderInterface::DEFAULT_RABBIT_MQ_VERSION
112
+ 'RabbitMQ version '
119
113
);
120
114
121
- $ this ->addOption (
122
- self ::OPTION_IS_TEST ,
123
- null ,
124
- InputOption::VALUE_NONE ,
125
- 'Generates ECE-Tools testing configuration (internal usage only) '
126
- );
127
-
128
115
parent ::configure ();
129
116
}
130
117
@@ -136,43 +123,28 @@ protected function configure()
136
123
*/
137
124
public function execute (InputInterface $ input , OutputInterface $ output )
138
125
{
139
- if ($ input ->getOption (self ::OPTION_IS_TEST )) {
140
- $ strategy = BuilderFactory::BUILDER_TEST ;
141
- $ path = $ this ->fileList ->getToolsDockerCompose ();
142
- } else {
143
- $ strategy = BuilderFactory::BUILDER_DEV ;
144
- $ path = $ this ->fileList ->getMagentoDockerCompose ();
145
- }
146
-
147
- $ builder = $ this ->builderFactory ->create ($ strategy );
148
-
149
- if ($ phpVersion = $ input ->getOption (self ::OPTION_PHP )) {
150
- $ builder ->setPhpVersion ($ phpVersion );
151
- }
152
-
153
- if ($ nginxVersion = $ input ->getOption (self ::OPTION_NGINX )) {
154
- $ builder ->setNginxVersion ($ nginxVersion );
155
- }
156
-
157
- if ($ dbVersion = $ input ->getOption (self ::OPTION_DB )) {
158
- $ builder ->setDbVersion ($ dbVersion );
159
- }
160
-
161
- if ($ redisVersion = $ input ->getOption (self ::OPTION_REDIS )) {
162
- $ builder ->setRedisVersion ($ redisVersion );
163
- }
164
-
165
- if ($ esVersion = $ input ->getOption (self ::OPTION_ES )) {
166
- $ builder ->setESVersion ($ esVersion );
167
- }
168
-
169
- if ($ rabbitMQVersion = $ input ->getOption (self ::OPTION_RABBIT_MQ )) {
170
- $ builder ->setRabbitMQVersion ($ rabbitMQVersion );
171
- }
172
-
173
- $ config = Yaml::dump ($ builder ->build (), 4 , 2 );
174
-
175
- $ this ->file ->filePutContents ($ path , $ config );
126
+ $ builder = $ this ->builderFactory ->create (BuilderFactory::BUILDER_DEV );
127
+ $ config = $ this ->configFactory ->create ();
128
+
129
+ $ map = [
130
+ self ::OPTION_PHP => BuilderInterface::PHP_VERSION ,
131
+ self ::OPTION_DB => BuilderInterface::DB_VERSION ,
132
+ self ::OPTION_NGINX => BuilderInterface::NGINX_VERSION ,
133
+ self ::OPTION_REDIS => BuilderInterface::REDIS_VERSION ,
134
+ self ::OPTION_ES => BuilderInterface::ES_VERSION ,
135
+ self ::OPTION_RABBIT_MQ => BuilderInterface::RABBIT_MQ_VERSION ,
136
+ ];
137
+
138
+ array_walk ($ map , function ($ key , $ option ) use ($ config , $ input ) {
139
+ if ($ value = $ input ->getOption ($ option )) {
140
+ $ config ->set ($ key , $ value );
141
+ }
142
+ });
143
+
144
+ $ this ->file ->filePutContents (
145
+ $ builder ->getConfigPath (),
146
+ Yaml::dump ($ builder ->build ($ config ), 4 , 2 )
147
+ );
176
148
177
149
$ output ->writeln ('<info>Configuration was built</info> ' );
178
150
}
0 commit comments