12
12
use BlameButton \LaravelDockerBuilder \Commands \GenerateQuestions \PhpExtensionsQuestion ;
13
13
use BlameButton \LaravelDockerBuilder \Commands \GenerateQuestions \PhpVersionQuestion ;
14
14
use BlameButton \LaravelDockerBuilder \Exceptions \InvalidOptionValueException ;
15
+ use BlameButton \LaravelDockerBuilder \Objects \Configuration ;
15
16
use BlameButton \LaravelDockerBuilder \Traits \InteractsWithTwig ;
16
17
use Symfony \Component \Console \Input \InputOption ;
17
18
@@ -26,25 +27,20 @@ class DockerGenerateCommand extends BaseCommand
26
27
public function handle (): int
27
28
{
28
29
try {
29
- $ phpVersion = app (PhpVersionQuestion::class)->getAnswer ($ this );
30
- $ phpExtensions = app (PhpExtensionsQuestion::class)->getAnswer ($ this , $ phpVersion );
31
- $ artisanOptimize = app (ArtisanOptimizeQuestion::class)->getAnswer ($ this );
32
- $ nodePackageManager = app (NodePackageManagerQuestion::class)->getAnswer ($ this );
33
- $ nodeBuildTool = $ nodePackageManager ? app (NodeBuildToolQuestion::class)->getAnswer ($ this ) : false ;
30
+ $ config = new Configuration (
31
+ phpVersion: $ phpVersion = app (PhpVersionQuestion::class)->getAnswer ($ this ),
32
+ phpExtensions: app (PhpExtensionsQuestion::class)->getAnswer ($ this , $ phpVersion ),
33
+ artisanOptimize: app (ArtisanOptimizeQuestion::class)->getAnswer ($ this ),
34
+ nodePackageManager: $ nodePackageManager = app (NodePackageManagerQuestion::class)->getAnswer ($ this ),
35
+ nodeBuildTool: $ nodePackageManager ? app (NodeBuildToolQuestion::class)->getAnswer ($ this ) : false ,
36
+ );
34
37
} catch (InvalidOptionValueException $ exception ) {
35
38
$ this ->error ($ exception ->getMessage ());
36
39
37
40
return self ::INVALID ;
38
41
}
39
42
40
- $ this ->info ('Configuration: ' );
41
- $ this ->table (['Key ' , 'Value ' ], [
42
- ['PHP version ' , "<comment> $ phpVersion</comment> " ],
43
- ['PHP extensions ' , implode (', ' , $ phpExtensions )],
44
- ['Artisan Optimize ' , '<comment> ' .json_encode ($ artisanOptimize ).'</comment> ' ],
45
- ['Node Package Manager ' , NodePackageManager::name ($ nodePackageManager )],
46
- ['Node Build Tool ' , $ nodePackageManager ? NodeBuildTool::name ($ nodeBuildTool ) : 'None ' ],
47
- ]);
43
+ $ this ->printConfigurationTable ($ config );
48
44
$ this ->newLine ();
49
45
50
46
if (! $ this ->option ('no-interaction ' ) && ! $ this ->confirm ('Does this look correct? ' , true )) {
@@ -53,39 +49,56 @@ public function handle(): int
53
49
return self ::SUCCESS ;
54
50
}
55
51
56
- $ this ->saveDockerfiles ([
57
- 'php_version ' => $ phpVersion ,
58
- 'php_extensions ' => implode (' ' , $ phpExtensions ),
59
- 'artisan_optimize ' => $ artisanOptimize ,
60
- 'node_package_manager ' => $ nodePackageManager ,
61
- 'node_build_tool ' => $ nodeBuildTool ,
62
- ]);
52
+ $ this ->saveDockerfiles ($ config );
63
53
$ this ->newLine ();
64
54
65
- $ command = array_filter ([
66
- 'php ' , 'artisan ' , 'docker:generate ' ,
67
- '-n ' , // --no-interaction
68
- '-p ' .$ phpVersion , // --php-version
69
- '-e ' .implode (', ' , $ phpExtensions ), // --php-extensions
70
- $ artisanOptimize ? '-o ' : null , // --optimize
71
- $ nodePackageManager ? '-m ' .$ nodePackageManager : null , // --node-package-manager
72
- $ nodePackageManager ? '-b ' .$ nodeBuildTool : null , // --node-build-tool
73
- ]);
74
-
75
55
$ this ->info ('Command to generate above configuration: ' );
76
- $ this ->comment (sprintf (' %s ' , implode (' ' , $ command )));
56
+ $ this ->comment (sprintf (' %s ' , implode (' ' , $ config -> getCommand () )));
77
57
78
58
return self ::SUCCESS ;
79
59
}
80
60
81
- private function saveDockerfiles (array $ context ): void
61
+ public function printConfigurationTable (Configuration $ config ): void
62
+ {
63
+ $ this ->info ('Configuration: ' );
64
+
65
+ $ this ->table (['Key ' , 'Value ' ], [
66
+ ['PHP version ' ,
67
+ '<comment> ' .$ config ->getPhpVersion ().'</comment> ' ,
68
+ ],
69
+ ['PHP extensions ' ,
70
+ implode (', ' , $ config ->getPhpExtensions ()),
71
+ ],
72
+ ['Artisan Optimize ' ,
73
+ '<comment> ' .json_encode ($ config ->isArtisanOptimize ()).'</comment> ' ,
74
+ ],
75
+ ['Node Package Manager ' ,
76
+ NodePackageManager::name ($ config ->getNodePackageManager ()),
77
+ ],
78
+ ['Node Build Tool ' ,
79
+ $ config ->getNodePackageManager ()
80
+ ? NodeBuildTool::name ($ config ->getNodeBuildTool ())
81
+ : 'None ' ,
82
+ ],
83
+ ]);
84
+ }
85
+
86
+ private function saveDockerfiles (Configuration $ config ): void
82
87
{
83
88
if (! is_dir ($ dir = base_path ('.docker ' ))) {
84
89
mkdir ($ dir );
85
90
}
86
91
87
92
$ this ->info ('Saving Dockerfiles: ' );
88
93
94
+ $ context = [
95
+ 'php_version ' => $ config ->getPhpVersion (),
96
+ 'php_extensions ' => implode (' ' , $ config ->getPhpExtensions ()),
97
+ 'artisan_optimize ' => $ config ->isArtisanOptimize (),
98
+ 'node_package_manager ' => $ config ->getNodePackageManager (),
99
+ 'node_build_tool ' => $ config ->getNodeBuildTool (),
100
+ ];
101
+
89
102
$ dockerfiles = [
90
103
'php.dockerfile ' => $ this ->render ('php.dockerfile.twig ' , $ context ),
91
104
'nginx.dockerfile ' => $ this ->render ('nginx.dockerfile.twig ' , $ context ),
0 commit comments