1212use BlameButton \LaravelDockerBuilder \Commands \GenerateQuestions \PhpExtensionsQuestion ;
1313use BlameButton \LaravelDockerBuilder \Commands \GenerateQuestions \PhpVersionQuestion ;
1414use BlameButton \LaravelDockerBuilder \Exceptions \InvalidOptionValueException ;
15+ use BlameButton \LaravelDockerBuilder \Objects \Configuration ;
1516use BlameButton \LaravelDockerBuilder \Traits \InteractsWithTwig ;
1617use Symfony \Component \Console \Input \InputOption ;
1718
@@ -26,25 +27,20 @@ class DockerGenerateCommand extends BaseCommand
2627 public function handle (): int
2728 {
2829 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+ );
3437 } catch (InvalidOptionValueException $ exception ) {
3538 $ this ->error ($ exception ->getMessage ());
3639
3740 return self ::INVALID ;
3841 }
3942
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 );
4844 $ this ->newLine ();
4945
5046 if (! $ this ->option ('no-interaction ' ) && ! $ this ->confirm ('Does this look correct? ' , true )) {
@@ -53,39 +49,56 @@ public function handle(): int
5349 return self ::SUCCESS ;
5450 }
5551
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 );
6353 $ this ->newLine ();
6454
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-
7555 $ this ->info ('Command to generate above configuration: ' );
76- $ this ->comment (sprintf (' %s ' , implode (' ' , $ command )));
56+ $ this ->comment (sprintf (' %s ' , implode (' ' , $ config -> getCommand () )));
7757
7858 return self ::SUCCESS ;
7959 }
8060
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
8287 {
8388 if (! is_dir ($ dir = base_path ('.docker ' ))) {
8489 mkdir ($ dir );
8590 }
8691
8792 $ this ->info ('Saving Dockerfiles: ' );
8893
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+
89102 $ dockerfiles = [
90103 'php.dockerfile ' => $ this ->render ('php.dockerfile.twig ' , $ context ),
91104 'nginx.dockerfile ' => $ this ->render ('nginx.dockerfile.twig ' , $ context ),
0 commit comments